Skip to content

langchain_graph_retriever

GraphRetriever

Bases: BaseRetriever

Retriever combining vector search and graph traversal.

The GraphRetriever class retrieves documents by first performing a vector search to identify relevant documents, followed by graph traversal to explore their connections. It supports multiple traversal strategies and integrates seamlessly with LangChain's retriever framework.

ATTRIBUTE DESCRIPTION
store

The adapter or vector store used for document retrieval.

TYPE: Adapter | VectorStore

edges

A list of EdgeSpec for use in creating a MetadataEdgeFunction, or an EdgeFunction.

TYPE: list[EdgeSpec] | EdgeFunction

strategy

The traversal strategy to use.

TYPE: Strategy

adapter cached property

adapter: Adapter

The adapter to use during traversals.

apply_extra

apply_extra() -> Self

Apply extra configuration to the traversal strategy.

This method captures additional fields provided in the model_extra argument and applies them to the current traversal strategy. Any extra fields are cleared after they are applied.

RETURNS DESCRIPTION
Self

The updated GraphRetriever instance.

Source code in packages/langchain-graph-retriever/src/langchain_graph_retriever/graph_retriever.py
@model_validator(mode="after")
def apply_extra(self) -> Self:
    """
    Apply extra configuration to the traversal strategy.

    This method captures additional fields provided in the `model_extra` argument
    and applies them to the current traversal strategy. Any extra fields are
    cleared after they are applied.

    Returns
    -------
    :
        The updated GraphRetriever instance.
    """
    if self.model_extra:
        self.strategy = dataclasses.replace(self.strategy, **self.model_extra)
        self.model_extra.clear()
    return self