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
Variants
There are some variations of this retriever:
-
Entity disambiguation — A naive Entity Extraction Pipeline will pull out any entities from texts. However, multiple entities might actually be referred to differently in the text but mean the same real-world entity. To keep the graph clean, an entity disambiguation step can be executed, where these entities are merged. Possible ways of doing this are described in Implementing ‘From Local to Global’ GraphRAG with Neo4j and LangChain: Constructing the Graph and Entity Linking and Relationship Extraction With Relik in LlamaIndex.
-
Question-guided/Schema-defined extraction — Instead of letting the LLM extract any kinds of entities and relationships, provide a set of questions or a fixed schema to guide the LLM to extract only the domain knowledge that is relevant for the application. This approach will narrow down the scope and the volume of the extraction (e.g., Introducing WhyHow.AI Open-Source Knowledge Graph Schema Library — Start Experimenting Faster).
-
Entity embeddings — When extracting the entities and the relationships using an LLM, we can instruct the LLM to also create/extract entity and relationship descriptions. These can be embedded and subsequently be used for the initial vector search and other guidance during traversal.
-
Ontology-driven traversal — Instead of hard-coding a traversal into your application code, you can provide an ontology for the traversal. This approach is explained in Going meta — Ep 24: KG+LLMs: Ontology driven RAG patterns.
Further reading
- Going Meta - Ep 23: Advanced RAG patterns with Knowledge Graphs (December 2023)