GraphVectorStore()A hybrid vector-and-graph graph store.
Document chunks support vector-similarity search as well as edges linking chunks based on structural and semantic properties.
.. versionadded:: 0.3.1
Add nodes to the graph store.
Add nodes to the graph store.
Run more texts through the embeddings and add to the vector store.
The Links present in the metadata field links will be extracted to create
the Node links.
Eg if nodes a and b are connected over a hyperlink https://some-url, the
function call would look like:
.. code-block:: python
store.add_texts(
ids=["a", "b"],
texts=["some text a", "some text b"],
metadatas=[
{
"links": [
Link.incoming(kind="hyperlink", tag="https://some-url")
]
},
{
"links": [
Link.outgoing(kind="hyperlink", tag="https://some-url")
]
},
],
)
Run more texts through the embeddings and add to the vector store.
The Links present in the metadata field links will be extracted to create
the Node links.
Eg if nodes a and b are connected over a hyperlink https://some-url, the
function call would look like:
.. code-block:: python
await store.aadd_texts(
ids=["a", "b"],
texts=["some text a", "some text b"],
metadatas=[
{
"links": [
Link.incoming(kind="hyperlink", tag="https://some-url")
]
},
{
"links": [
Link.outgoing(kind="hyperlink", tag="https://some-url")
]
},
],
)
Run more documents through the embeddings and add to the vector store.
The Links present in the document metadata field links will be extracted to
create the Node links.
Eg if nodes a and b are connected over a hyperlink https://some-url, the
function call would look like:
.. code-block:: python
store.add_documents(
[
Document(
id="a",
page_content="some text a",
metadata={
"links": [
Link.incoming(kind="hyperlink", tag="http://some-url")
]
}
),
Document(
id="b",
page_content="some text b",
metadata={
"links": [
Link.outgoing(kind="hyperlink", tag="http://some-url")
]
}
),
]
)
Run more documents through the embeddings and add to the vector store.
The Links present in the document metadata field links will be extracted to
create the Node links.
Eg if nodes a and b are connected over a hyperlink https://some-url, the
function call would look like:
.. code-block:: python
store.add_documents(
[
Document(
id="a",
page_content="some text a",
metadata={
"links": [
Link.incoming(kind="hyperlink", tag="http://some-url")
]
}
),
Document(
id="b",
page_content="some text b",
metadata={
"links": [
Link.outgoing(kind="hyperlink", tag="http://some-url")
]
}
),
]
)
Retrieve documents from traversing this graph store.
First, k nodes are retrieved using a search for each query string.
Then, additional nodes are discovered up to the given depth from those
starting nodes.
Retrieve documents from traversing this graph store.
First, k nodes are retrieved using a search for each query string.
Then, additional nodes are discovered up to the given depth from those
starting nodes.
Retrieve documents from this graph store using MMR-traversal.
This strategy first retrieves the top fetch_k results by similarity to
the question. It then selects the top k results based on
maximum-marginal relevance using the given lambda_mult.
At each step, it considers the (remaining) documents from fetch_k as
well as any documents connected by edges to a selected document
retrieved based on similarity (a "root").
Retrieve documents from this graph store using MMR-traversal.
This strategy first retrieves the top fetch_k results by similarity to
the question. It then selects the top k results based on
maximum-marginal relevance using the given lambda_mult.
At each step, it considers the (remaining) documents from fetch_k as
well as any documents connected by edges to a selected document
retrieved based on similarity (a "root").
Return GraphVectorStoreRetriever initialized from this GraphVectorStore.