Retrievers providing both unstructured (similarity-search on vectors) and structured (traversal of metadata properties).
Graph RAG provides retrievers combining vector-search (for unstructured similarity) and traversal (for structured relationships in metadata). These retrievers are implemented using the metadata search functionality of existing vector stores, allowing you to traverse your existing vector store!
The core library (graph-retriever
) supports can be used in generic Python applications, while langchain-graph-retriever
provides langchain-specific functionality.
Install langchain-graph-retriever
(or add to your Python dependencies).
pip install langchain-graph-retriever
Wrap your existing vector store to enable graph retrieval:
from langchain_graph_retriever import GraphRetriever
retriever = GraphRetriever(
# Adapt AstraDBVectorStore for use with Graph Retrievers.
# Exposes functionality of the underlying store that is otherwise not available.
store = store,
# Define the relationships to navigate:
# 1. From nodes with a list of `mentions` to the nodes with the corresponding `ids`.
# 2. From nodes with a list of related `entities` to other nodes with the same entities.
edges = [("mentions", "id"), "entities"],
)
retriever.invoke("where is Santa Clara?")