Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow search in ChromaDocumentStore without metadata #863

Merged
merged 10 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,9 @@ def _query_result_to_documents(result: QueryResult) -> List[List[Document]]:
}

# prepare metadata
if metadatas := result.get("metadatas"):
document_dict["meta"] = dict(metadatas[i][j])
metadatas = result.get("metadatas")
if metadatas and metadatas[i][j] is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it ever happen that metadatas size is shorter than i? And metadatas[i] is shorter than j? 🤔

Cause if it can happen this could fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an exception here as discussed.

document_dict["meta"] = metadatas[i][j]

if embeddings := result.get("embeddings"):
document_dict["embedding"] = np.array(embeddings[i][j])
Expand Down
9 changes: 9 additions & 0 deletions integrations/chroma/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ def test_delete_not_empty_nonexisting(self, document_store: ChromaDocumentStore)

assert document_store.filter_documents(filters={"id": doc.id}) == [doc]

def test_document_store_search_without_metadata(self):
document_store = ChromaDocumentStore()
document_store.write_documents([Document(content=e) for e in ["First document", "Second document"]])
result = document_store.search(["First document"], top_k=1)

# Assertions to verify correctness
assert len(result) == 1
assert result[0][0].content == "First document"

@pytest.mark.integration
def test_to_json(self, request):
ds = ChromaDocumentStore(
Expand Down
Loading