Skip to content

Graph-Enhanced Vector Search

Alternative Names

  • Graph + Vector
  • Augmented Vector Search

Required Graph Shape

Lexical Graph with Extracted Entities

Context

The biggest problem with basic GraphRAG patterns is finding all relevant context necessary to answer a question. The context can be spread across many chunks not being found by the search. Relating the real-world entities from the chunks to each other and retrieving these relationships together with a vector search provides additional context about these entities that the chunks refer to. They can also be used to relate chunks to each other through the entity network.

Description

The user question is embedded using the same embedder that has been used before to create embeddings. A vector similarity search is executed on the Chunk embeddings to find k (number previously configured by developer / user) most similar Chunks. A traversal starting at the found chunks is executed to retrieve more context.

Usage

This pattern is useful for retrieving more enriched context than the results of executing only a vector search as in e.g. Basic Retrievers or Parent-Child Retrievers. The additional traversal retrieves the interaction of entities within the provided data which reveals much richer information than the retrieval of specific text chunks. Naturally, the preprocessing for this GraphRAG pattern is effort. Furthermore, the amount of context that is returned by the Graph Traversal can be much larger context which the LLM needs be able to process.

Required pre-processing

Use an LLM to execute entity and relationship extraction on the chunks. Import the retrieved triples into the graph.

Retrieval Query

MATCH (node)-[:PART_OF]->(d:Document)
CALL { WITH node
MATCH (node)-[:HAS_ENTITY]->(e)
MATCH path=(e)(()-[rels:!HAS_ENTITY&!PART_OF]-()){0,2}(:!Chunk&!Document)
RETURN …}
RETURN

Variants

There are some variations of this retriever:

Further reading

Existing Implementations

Example Implementations