-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): update document in vector store (#210)
- Loading branch information
1 parent
7f82f95
commit 2816e60
Showing
10 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/ragbits-core/tests/integration/vector_stores/test_vector_store.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from unittest.mock import AsyncMock | ||
|
||
import pytest | ||
from chromadb import EphemeralClient | ||
from qdrant_client import AsyncQdrantClient | ||
|
||
from ragbits.core.vector_stores.base import VectorStore | ||
from ragbits.core.vector_stores.chroma import ChromaVectorStore | ||
from ragbits.core.vector_stores.in_memory import InMemoryVectorStore | ||
from ragbits.core.vector_stores.qdrant import QdrantVectorStore | ||
from ragbits.document_search import DocumentSearch | ||
from ragbits.document_search.documents.document import DocumentMeta | ||
from ragbits.document_search.documents.sources import LocalFileSource | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"vector_store", | ||
[ | ||
InMemoryVectorStore(), | ||
ChromaVectorStore( | ||
client=EphemeralClient(), | ||
index_name="test_index_name", | ||
), | ||
QdrantVectorStore( | ||
client=AsyncQdrantClient(":memory:"), | ||
index_name="test_index_name", | ||
), | ||
], | ||
) | ||
async def test_handling_document_ingestion_with_different_content_and_verifying_replacement( | ||
vector_store: VectorStore, | ||
) -> None: | ||
document_1_content = "This is a test sentence and it should be in the vector store" | ||
document_2_content = "This is another test sentence and it should be removed from the vector store" | ||
document_2_new_content = "This is one more test sentence and it should be added to the vector store" | ||
|
||
document_1 = DocumentMeta.create_text_document_from_literal(document_1_content) | ||
document_2 = DocumentMeta.create_text_document_from_literal(document_2_content) | ||
|
||
embedder = AsyncMock() | ||
embedder.embed_text.return_value = [[0.0], [0.0]] | ||
document_search = DocumentSearch( | ||
embedder=embedder, | ||
vector_store=vector_store, | ||
) | ||
await document_search.ingest([document_1, document_2]) | ||
|
||
if isinstance(document_2.source, LocalFileSource): | ||
document_2_path = document_2.source.path | ||
with open(document_2_path, "w") as file: | ||
file.write(document_2_new_content) | ||
|
||
await document_search.ingest([document_2]) | ||
|
||
document_contents = {entry.key for entry in await vector_store.list()} | ||
|
||
assert document_1_content in document_contents | ||
assert document_2_new_content in document_contents | ||
assert document_2_content not in document_contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters