> ## Documentation Index
> Fetch the complete documentation index at: https://docs.falkordb.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> FalkorDB is a graph database that speaks the Redis protocol. Queries are issued as OpenCypher through the GRAPH.QUERY and GRAPH.RO_QUERY commands, not over Bolt or a SQL connection.
> FalkorDB implements a subset of OpenCypher with proprietary extensions. Do not assume Neo4j-only syntax or procedures are available — check /cypher/cypher-support and /cypher/known-limitations before using a clause.
> FalkorDB is the successor to RedisGraph, but they are separate products. Do not present RedisGraph commands, versions, or limitations as current FalkorDB behavior.
> Use the official clients listed in /getting-started/clients rather than generic Redis or Neo4j drivers, and prefer the language the user is already working in.
> Configuration parameters are set with GRAPH.CONFIG SET or at startup; cite the exact parameter name from /getting-started/configuration rather than inventing one.
> This site covers four products: FalkorDB (core), FalkorDB Cloud, FalkorDB Enterprise, and the GraphRAG SDK. Name which one an answer applies to, since setup and operations differ.

# sim.jaccard

> Computes the Jaccard similarity coefficient between two lists, returning a score between 0 (no overlap) and 1 (identical sets).

## Description

Computes the Jaccard similarity coefficient between two sets (lists). The Jaccard index measures the similarity between two sets by dividing the size of their intersection by the size of their union. It returns a value between 0 (no similarity) and 1 (identical sets).

## Syntax

```cypher theme={null}
flex.sim.jaccard(list1, list2)
```

## Parameters

| Parameter | Type | Required | Description                |
| --------- | ---- | -------- | -------------------------- |
| `list1`   | list | Yes      | The first list to compare  |
| `list2`   | list | Yes      | The second list to compare |

## Returns

**Type:** number (float)

A value between 0 and 1 representing the Jaccard similarity coefficient:

* `1.0` indicates identical sets
* `0.0` indicates no common elements
* Returns `null` for invalid inputs

## Examples

### Example 1: Basic Set Similarity

```cypher theme={null}
// Compare two tag lists
RETURN flex.sim.jaccard(['tag1', 'tag2', 'tag3'], ['tag2', 'tag3', 'tag4']) AS similarity
```

**Output:**

```text theme={null}
similarity
----------
0.5
```

(2 common elements / 4 total unique elements = 0.5)

### Example 2: Finding Similar Documents by Tags

```cypher theme={null}
// Find documents with similar tags to a reference document
MATCH (ref:Document {id: 'doc123'})
MATCH (other:Document)
WHERE other.id <> ref.id
WITH ref, other, flex.sim.jaccard(ref.tags, other.tags) AS similarity
WHERE similarity > 0.3
RETURN other.title, similarity
ORDER BY similarity DESC
LIMIT 10
```

### Example 3: User Interest Matching

```cypher theme={null}
// Find users with similar interests
MATCH (u1:User {id: $userId})
MATCH (u2:User)
WHERE u1 <> u2
WITH u1, u2, flex.sim.jaccard(u1.interests, u2.interests) AS match_score
WHERE match_score > 0.5
RETURN u2.name, u2.interests, match_score
ORDER BY match_score DESC
```

## Notes

* Treats input lists as sets (duplicates within each list don't affect the result)
* Returns `null` if either input is not an array
* Order of elements doesn't matter
* Works with any comparable data types (strings, numbers, etc.)
* Ideal for comparing categorical attributes, tags, or interest lists

## See Also

* [text.levenshtein](/udfs/flex/text/levenshtein) - Edit distance for string comparison
* [coll.intersection](/udfs/flex/collections/intersection) - Get common elements between sets
* [coll.union](/udfs/flex/collections/union) - Combine sets

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="What does a Jaccard score of 0.5 mean?">
    It means half of the combined unique elements are shared between the two sets. The formula is `|intersection| / |union|`.
  </Accordion>

  <Accordion title="Does the order of elements matter?">
    No. Jaccard treats inputs as sets, so element order and duplicates within a single list do not affect the result.
  </Accordion>

  <Accordion title="What types of elements can I compare?">
    Any comparable data types including strings, numbers, and booleans. Both lists should contain the same type of elements for meaningful comparison.
  </Accordion>
</AccordionGroup>
