Skip to content

feat(ibm_db): support all 6 Db2 vector distance metrics - #4045

Open
GeetikaChughIBM wants to merge 3 commits into
deepset-ai:mainfrom
GeetikaChughIBM:feat/support-all-db2-distance-metrics
Open

GeetikaChughIBM wants to merge 3 commits into
deepset-ai:mainfrom
GeetikaChughIBM:feat/support-all-db2-distance-metrics

Conversation

@GeetikaChughIBM

@GeetikaChughIBM GeetikaChughIBM commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extends the IBM Db2 document store to support all 6 distance metrics
available in Db2's VECTOR_DISTANCE function, up from the previous 3.

Changes

document_store.py

  • Expanded the distance_metric type annotation from
    Literal["EUCLIDEAN", "COSINE", "MANHATTAN"] to include all 6:
    COSINE, DOT, EUCLIDEAN, EUCLIDEAN_SQUARED, HAMMING, MANHATTAN
  • Updated the docstring to document all supported values

test_document_store.py

  • Added unit tests (TestIBMDb2DocumentStoreUnit) verifying:
    • All 6 metrics can be configured, serialized, and round-tripped via to_dict / from_dict
    • _embedding_retrieval emits the correct VECTOR_DISTANCE(..., <METRIC>) SQL fragment for each metric
  • Added integration tests (TestDocumentStore) verifying against a real Db2 instance:
    • test_all_distance_metrics_return_ranked_results — correct ranking and score ordering for each metric
    • test_all_distance_metrics_respect_filters — metadata filters work correctly alongside each metric

Testing

All 12 integration tests verified passing against a real Db2 instance

Closes #4046

Add two parametrized integration tests inside the existing TestDocumentStore
class covering all 6 supported distance metrics (COSINE, DOT, EUCLIDEAN,
EUCLIDEAN_SQUARED, HAMMING, MANHATTAN):

- test_all_distance_metrics_return_ranked_results: verifies correct ranking,
  finite scores, and ORDER BY ASC ordering for each metric
- test_all_distance_metrics_respect_filters: verifies metadata filters work
  correctly alongside each distance metric

Each test creates an isolated table (embedding_dim=4) via the connection_config
fixture, runs retrieval assertions, then drops the table.

All 12 tests verified passing against a real Db2 instance.
@GeetikaChughIBM
GeetikaChughIBM requested a review from a team as a code owner October 2, 2026 21:18
@GeetikaChughIBM
GeetikaChughIBM requested review from sjrl and removed request for a team October 2, 2026 21:18
@github-actions github-actions Bot added integration:ibm-db type:documentation Improvements or additions to documentation labels Oct 2, 2026
- Move DuplicatePolicy import to correct sorted position (I001)
- Remove unused noqa BLE001 directives (RUF100)
- Collapse multi-line f-strings and remove alignment spaces to satisfy ruff formatter
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Coverage report (ibm_db)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/ibm_db/src/haystack_integrations/document_stores/ibm_db
  document_store.py
Project Total  

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

This branch has not been deployed

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

Labels

integration:ibm-db type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support all 6 Db2 vector distance metrics in IBMDb2DocumentStore

1 participant