Skip to content

Commit

Permalink
Add test to ensure indexing twice doesnt change number of documents
Browse files Browse the repository at this point in the history
  • Loading branch information
conradocloudera committed Nov 22, 2024
1 parent 24fa1f8 commit 37e4221
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions llm-service/app/routers/index/data_source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,6 @@ def download_and_index(
embedding_model=models.get_embedding_model(),
chunks_vector_store=self.chunks_vector_store,
)
# Delete to avoid duplicates
self.chunks_vector_store.delete_document(request.document_id)
indexer.index_file(file_path, request.document_id)
34 changes: 34 additions & 0 deletions llm-service/app/tests/routers/index/test_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,40 @@ def test_create_document(
)
assert len(vectors.nodes or []) == 1

@staticmethod
def test_double_create_document(
client: TestClient,
index_document_request_body: dict[str, Any],
document_id: str,
data_source_id: int,
) -> None:
"""Test POST /download-and-index."""
response = client.post(
f"/data_sources/{data_source_id}/documents/download-and-index",
json=index_document_request_body,
)

assert response.status_code == 200
assert document_id is not None

response = client.get(f"/data_sources/{data_source_id}/size")
assert response.status_code == 200
size1 = response.json()

response = client.post(
f"/data_sources/{data_source_id}/documents/download-and-index",
json=index_document_request_body,
)

assert response.status_code == 200
assert document_id is not None

response = client.get(f"/data_sources/{data_source_id}/size")
assert response.status_code == 200
size2 = response.json()

assert size2 == size1

@staticmethod
def test_delete_data_source(
client: TestClient,
Expand Down

0 comments on commit 37e4221

Please sign in to comment.