Skip to content
Snippets Groups Projects
Unverified Commit 00218ccb authored by Will Deaderick's avatar Will Deaderick Committed by GitHub
Browse files

Opensearch test and documentation (#11981)

parent 70828c73
No related branches found
No related tags found
No related merge requests found
......@@ -358,12 +358,12 @@ class OpensearchVectorClient:
is_aoss=self.is_aoss,
)
async def delete_doc_id(self, doc_id: str) -> None:
async def delete_by_doc_id(self, doc_id: str) -> None:
"""
Delete a document.
Deletes all OpenSearch documents corresponding to the given LlamaIndex `Document` ID.
Args:
doc_id (str): document id
doc_id (str): a LlamaIndex `Document` id
"""
search_query = {
"query": {"term": {"metadata.doc_id.keyword": {"value": doc_id}}}
......@@ -494,10 +494,10 @@ class OpensearchVectorStore(BasePydanticVectorStore):
def delete(self, ref_doc_id: str, **delete_kwargs: Any) -> None:
"""
Delete nodes using with ref_doc_id.
Delete nodes using a ref_doc_id.
Args:
ref_doc_id (str): The doc_id of the document to delete.
ref_doc_id (str): The doc_id of the document whose nodes should be deleted.
"""
asyncio.get_event_loop().run_until_complete(
......@@ -506,13 +506,13 @@ class OpensearchVectorStore(BasePydanticVectorStore):
async def adelete(self, ref_doc_id: str, **delete_kwargs: Any) -> None:
"""
Async delete nodes using with ref_doc_id.
Async delete nodes using a ref_doc_id.
Args:
ref_doc_id (str): The doc_id of the document to delete.
ref_doc_id (str): The doc_id of the document whose nodes should be deleted.
"""
await self._client.delete_doc_id(ref_doc_id)
await self._client.delete_by_doc_id(ref_doc_id)
def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResult:
"""
......
......@@ -4,7 +4,7 @@ import pytest
import uuid
from typing import List, Generator
from llama_index.core.schema import TextNode
from llama_index.core.schema import NodeRelationship, RelatedNodeInfo, TextNode
from llama_index.vector_stores.opensearch import (
OpensearchVectorClient,
OpensearchVectorStore,
......@@ -68,7 +68,7 @@ def node_embeddings() -> List[TextNode]:
TextNode(
text="lorem ipsum",
id_="c330d77f-90bd-4c51-9ed2-57d8d693b3b0",
# relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="test-0")},
relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="test-0")},
metadata={
"author": "Stephen King",
"theme": "Friendship",
......@@ -78,7 +78,7 @@ def node_embeddings() -> List[TextNode]:
TextNode(
text="lorem ipsum",
id_="c3d1e1dd-8fb4-4b8f-b7ea-7fa96038d39d",
# relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="test-1")},
relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="test-1")},
metadata={
"director": "Francis Ford Coppola",
"theme": "Mafia",
......@@ -88,7 +88,7 @@ def node_embeddings() -> List[TextNode]:
TextNode(
text="lorem ipsum",
id_="c3ew11cd-8fb4-4b8f-b7ea-7fa96038d39d",
# relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="test-2")},
relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="test-2")},
metadata={
"director": "Christopher Nolan",
},
......@@ -97,8 +97,8 @@ def node_embeddings() -> List[TextNode]:
TextNode(
text="I was taught that the way of progress was neither swift nor easy.",
id_="0b31ae71-b797-4e88-8495-031371a7752e",
# relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="text-3")},
metadate={
relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="test-3")},
metadata={
"author": "Marie Curie",
},
embedding=[0.0, 0.0, 0.9],
......@@ -109,8 +109,8 @@ def node_embeddings() -> List[TextNode]:
+ " Curiosity has its own reason for existing."
),
id_="bd2e080b-159a-4030-acc3-d98afd2ba49b",
# relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="text-4")},
metadate={
relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="test-4")},
metadata={
"author": "Albert Einstein",
},
embedding=[0.0, 0.0, 0.5],
......@@ -121,8 +121,8 @@ def node_embeddings() -> List[TextNode]:
+ " I am a free human being with an independent will."
),
id_="f658de3b-8cef-4d1c-8bed-9a263c907251",
# relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="text-5")},
metadate={
relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="test-5")},
metadata={
"author": "Charlotte Bronte",
},
embedding=[0.0, 0.0, 0.3],
......@@ -153,6 +153,6 @@ def test_functionality(
query_result = os_store.query(query)
assert query_result.nodes
assert query_result.nodes[0].get_content() == exp_node.text
# delete
os_store.delete(exp_node.id_)
# delete one node using its associated doc_id
os_store.delete("test-1")
assert count_docs_in_index(os_store) == len(node_embeddings) - 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment