Skip to main content
FalkorDB’s vector index uses the HNSW (Hierarchical Navigable Small World) algorithm with cosine similarity or Euclidean distance, supporting 1–4096-dimensional vectors. With the introduction of the vector data-type a new type of index was introduced. A vector index is a dedicated index for indexing and searching through vectors. To create this type of index use the following syntax:
The options are:
For example, to create a vector index over all Product nodes description attribute use the following syntax:
Similarly to create a vector index over all Call relationships summary attribute use the following syntax:
Important: When creating a vector index, both the vector dimension and similarity function must be provided. Currently, the only supported similarity functions are ‘euclidean’ or ‘cosine’.

Understanding Vector Index Parameters

Required Parameters

  • dimension: The length of the vectors to be indexed. Must match the dimensionality of your embeddings (e.g., 128, 384, 768, 1536).
  • similarityFunction: The distance metric used for similarity search:
    • euclidean: Euclidean distance (L2 norm). Best for embeddings where magnitude matters.
    • cosine: Cosine similarity. Best for normalized embeddings where direction matters more than magnitude.
Note: The supported dimension range is 1–4096.

Optional Parameters

These parameters control the HNSW (Hierarchical Navigable Small World) index structure:
  • M (default: 16): Maximum number of connections per node in the graph
    • Higher values improve recall but increase memory usage and build time
    • Recommended range: 12-48
    • Use 16-32 for most applications
  • efConstruction (default: 200): Number of candidates evaluated during index construction
    • Higher values improve index quality but slow down indexing
    • Recommended range: 100-400
    • Use 200-300 for balanced quality/speed
  • efRuntime (default: 10): Number of candidates evaluated during search
    • Higher values improve recall but slow down queries
    • Can be adjusted per-query for speed/accuracy tradeoffs
    • Recommended: Start with 10, increase if recall is insufficient

See Also

Tip: Use a vector index for semantic similarity search, a full-text index for keyword search, and a range index for exact or range-based property lookups.

Inserting vectors

To create a new vector use the vecf32 function as follows:
The above query creates a new Product node with a description attribute containing a vector.

Query vector index

Vector indices are used to search for similar vectors to a given query vector using the similarity function as a measure of “distance”. To query the index use either db.idx.vector.queryNodes for node retrieval or db.idx.vector.queryRelationships for relationships.
To query up to 10 similar Product descriptions to a given query description vector issue the following procedure call:
The procedure can yield both the indexed entity assigned to the found similar vector in addition to a similarity score of that entity.

Deleting a vector index

To remove a vector index, simply issue the drop index command as follows:
For example, to drop the vector index over Product description, invoke:

Index Management

Listing Vector Indexes

To view all indexes (including vector) in your graph, use:
Vector indexes are marked with type VECTOR and show the dimension and similarity function in the options field.

Verifying Vector Index Usage

To verify that a vector index is being used, examine the query execution plan:

Performance Tradeoffs and Best Practices

When to Use Vector Indexes

Vector indexes are essential for:
  • Semantic search: Finding similar items based on meaning, not just keywords
  • Recommendation systems: Discovering similar products, content, or users
  • RAG (Retrieval Augmented Generation): Retrieving relevant context for LLMs
  • Duplicate detection: Finding near-duplicate items based on embeddings
  • Image/audio similarity: When using vision or audio embedding models

Performance Considerations

Benefits:
  • Enables efficient approximate nearest neighbor (ANN) search
  • Scales to millions of vectors with sub-linear query time
  • Supports both node and relationship vectors
Costs:
  • Memory usage: Vector indexes are memory-intensive
    • A 1M vector index with 768 dimensions (float32) requires ~3GB of memory
    • Formula: vectors × dimensions × 4 bytes + HNSW overhead (~20%)
  • Build time: Index construction can be slow for large datasets
  • Approximate results: Returns approximate (not exact) nearest neighbors
  • No support for filtering: Vector queries don’t combine well with property filters
Recommendations:
  • Choose appropriate vector dimensions (balance between quality and cost)
  • Use cosine similarity for normalized embeddings (e.g., from OpenAI, Sentence Transformers)
  • Use euclidean distance for unnormalized data
  • Tune M and efConstruction based on your accuracy requirements
  • Consider batch indexing for large datasets
  • Monitor memory usage carefully

Similarity Function Tradeoffs

Cosine Similarity:
  • Best for: Text embeddings, normalized vectors
  • Measures: Angular distance between vectors
  • Range: -1 to 1 (1 = identical direction)
  • Use when: Vector magnitude is not meaningful
Euclidean Distance:
  • Best for: Unnormalized data, physical measurements
  • Measures: Straight-line distance between vectors
  • Range: 0 to ∞ (0 = identical)
  • Use when: Both direction and magnitude matter

Troubleshooting

Common Issues:
  1. Dimension mismatch: Ensure all vectors have the same dimension as specified in the index
  2. Wrong similarity function: Use cosine for normalized vectors, euclidean for unnormalized
  3. Poor recall: Increase efRuntime or efConstruction parameters
  4. Slow queries: Decrease efRuntime or reduce k (number of results)
  5. High memory usage: Reduce M parameter or use lower-dimensional embeddings

Frequently Asked Questions

FalkorDB supports euclidean distance and cosine similarity. Use cosine for normalized vectors (e.g., from embedding models) and euclidean for unnormalized vectors.
Use CALL db.idx.vector.queryNodes('Label', 'attribute', k, vecf32([...])) where k is the number of nearest neighbors to return and the last argument is your query vector.
Vector indexes support any dimension, but all vectors for a given index must have the same dimension as specified during index creation. Mismatched dimensions will cause errors.
Yes. Use CALL db.idx.vector.queryRelationships('RelType', 'attribute', k, query_vector) to perform similarity search on relationship vector properties.
Increase the efRuntime parameter for higher recall at the cost of query latency. For build-time quality, increase efConstruction and M parameters when creating the index.