Skip to content

test: FAISS - increase unit tests coverage - #3795

Draft
julian-risch wants to merge 1 commit into
mainfrom
test/faiss-unit-coverage
Draft

test: FAISS - increase unit tests coverage#3795
julian-risch wants to merge 1 commit into
mainfrom
test/faiss-unit-coverage

Conversation

@julian-risch

Copy link
Copy Markdown
Member

Related Issues

Proposed Changes:

  • Add unit tests for _check_condition (the filter matcher, was 24%), search scoring and the -1 padding, the write and delete policies, the metadata aggregation family, and save/load. FAISS runs in-process, so these drive a real store and need no mocks.
  • Add pytest-asyncio to the test environment; FAISSEmbeddingRetriever.run_async had no test at all because the dependency was missing.
  • Remove test_check_condition_invalid_structure_raises_filter_error from test_document_store.py; its four cases are a subset of the new parametrized version.

How did you test it?

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes — n/a
  • I added unit tests and updated the docstrings
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test:.

Cover the code paths that were only reachable through the
integration-marked tests, which the unit coverage badge excludes. FAISS
runs in-process, so these need no mocks: they drive a real in-memory
store and use tmp_path for persistence.

- _check_condition: every logical and comparison operator, the
  missing-field and None-value short circuits, mixed int/float
  comparison, and all eleven FilterError paths
- _get_doc_value: content, id, meta. prefix, attribute fallback, and
  unknown fields
- search: ranking, the 1/(1+distance) score for a Flat index, top_k,
  post-retrieval filtering, the -1 padding FAISS returns when top_k
  exceeds the index size, and that the stored document is not mutated
- write_documents OVERWRITE and SKIP policies, delete_documents,
  delete_all_documents, and their effect on the index
- the metadata aggregation family, including documents missing the field
- save/load round trip, the missing-file error, and the out-of-sync warning
- to_dict/from_dict on both the store and the retriever
- the retriever's run, filter policies, and run_async

run_async had no test at all because pytest-asyncio was missing from the
test environment; it is added here.

Unit coverage: 32% -> 99%.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added integration:faiss type:documentation Improvements or additions to documentation labels Aug 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report (faiss)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/faiss/src/haystack_integrations/components/retrievers/faiss
  embedding_retriever.py
  integrations/faiss/src/haystack_integrations/document_stores/faiss
  document_store.py
Project Total  

This report was generated by python-coverage-comment-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:faiss type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant