Skip to content

feat: Added IBM Db2 vector store integration#3518

Open
priyanshu-krishnan1 wants to merge 16 commits into
deepset-ai:mainfrom
GeetikaChughIBM:ibm-db2-vectorstore
Open

feat: Added IBM Db2 vector store integration#3518
priyanshu-krishnan1 wants to merge 16 commits into
deepset-ai:mainfrom
GeetikaChughIBM:ibm-db2-vectorstore

Conversation

@priyanshu-krishnan1

Copy link
Copy Markdown

Related Issues

  • Adds IBM Db2 vector store integration for Haystack

Proposed Changes:

Added a new integration for IBM Db2 database with vector search capabilities:

  • Db2DocumentStore: Document store with vector similarity search using DB2's native VECTOR type
  • Db2EmbeddingRetriever: Retriever component for semantic search with metadata filtering
  • FilterTranslator: Converts Haystack filters to DB2 SQL with support for complex logical operators

How did you test it?

  • Unit tests for document store operations, filter translation, and connection handling
  • Integration tests using Docker Compose with IBM Db2 Community Edition
  • Haystack document store mixin tests
  • Manual verification with local Db2 instance

Notes for the reviewer

  • Follows standard Haystack document store patterns (similar to pgvector, oracle)

Checklist

@priyanshu-krishnan1 priyanshu-krishnan1 requested a review from a team as a code owner July 1, 2026 14:31
@priyanshu-krishnan1 priyanshu-krishnan1 requested review from bogdankostic and removed request for a team July 1, 2026 14:31
@socket-security

socket-security Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedpypi/​ibm-db@​3.2.984100100100100

View full report

@github-actions github-actions Bot added topic:CI type:documentation Improvements or additions to documentation labels Jul 1, 2026
@sjrl sjrl requested review from sjrl and removed request for bogdankostic July 1, 2026 15:37
@sjrl

sjrl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Hey @bogdankostic I was already reviewing this in #3458 (comment) so I'll take this over

@sjrl sjrl self-assigned this Jul 1, 2026
Comment thread integrations/ibm_db/pydoc/config_docusaurus.yml
Comment thread integrations/ibm_db/pyproject.toml Outdated
Comment thread integrations/ibm_db/tests/test_document_store_unit.py Outdated
Comment thread integrations/ibm_db/tests/test_filters.py
Comment thread integrations/ibm_db/tests/test_embedding_retriever.py Outdated
Comment thread integrations/ibm_db/tests/test_embedding_retriever.py Outdated
Comment thread integrations/ibm_db/tests/test_embedding_retriever.py Outdated
Comment on lines +20 to +26
Use inside a Haystack pipeline after a text embedder::

pipeline.add_component("embedder", SentenceTransformersTextEmbedder())
pipeline.add_component("retriever", Db2EmbeddingRetriever(
document_store=store, top_k=5
))
pipeline.connect("embedder.embedding", "retriever.query_embedding")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please wrap python code in code blocks.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Done! The example in the class docstring is now wrapped in a .. code-block:: python directive.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry I didn't provide more context in my earlier comment but could we enclose with triple-backticks instead of .. code-block::. Our API doc strings don't support the .. code-block:: syntax.

Comment thread integrations/ibm_db/README.md
@CLAassistant

CLAassistant commented Jul 2, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sjrl

sjrl commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Hey @priyanshu-krishnan1 and @GeetikaChughIBM thanks for the updates! @GeetikaChughIBM would it be possible for you to sign the CLA agreement as well? #3518 (comment)

GeetikaChughIBM and others added 6 commits July 3, 2026 12:11
* test: replace live DB fixture with mocked Db2DocumentStore in serialization tests

* refactor: move util method unit tests to test_document_store.py and delete test_document_store_unit.py

* Remove dead code: unreachable return in count_unique_metadata_by_filter_async

* Fix typo: ____cause__ -> __cause__ in hasattr check

* Move empty documents check after isinstance check in write_documents

* Add missing LICENSE.txt (Apache 2.0) to ibm_db integration

* Wrap Python example in proper code-block directive in Db2EmbeddingRetriever docstring

* Convert run() docstring to Haystack :param:/:returns: style in Db2EmbeddingRetriever

* Add missing __init__ docstring with :param:/:raises: to Db2EmbeddingRetriever

* Add full :param:/:returns: docstring to run_async() in Db2EmbeddingRetriever

* Simplify README to lightweight format following the conventions

* Fix line length in run_async() docstring to pass fmt-check

---------

Co-authored-by: priyanshu-krishnan1 <priyanshu.krishnan1@ibm.com>
…ecret for credentials

* refactor(ibm_db): inline connection params and use Secret for credentials

Remove the Db2ConnectionConfig dataclass and pass connection parameters
directly to Db2DocumentStore.__init__(). username and password are now
required Secret values (oracle-style) and are serialized as env-var
references, never as plaintext. Tests use Secret.from_token in the live
fixture; serialization tests build their own env-var-backed store.

* refactor(ibm_db): rename Db2DocumentStore/Db2EmbeddingRetriever to IBMDb2 prefix

Renames the public classes to IBMDb2DocumentStore and IBMDb2EmbeddingRetriever
(and their test classes), updating imports, __all__ exports, serialization
type strings, and docstrings.
@GeetikaChughIBM

Copy link
Copy Markdown

Hey @priyanshu-krishnan1 thanks for opening the new PR! I've left an initial set of comments.

Also I noticed that the LICENSE.txt file is missing. Please add one. You can copy the one at the top-level of the repo which is here

Added LICENSE.txt copied from the top-level repo license (Apache 2.0).

@GeetikaChughIBM

Copy link
Copy Markdown

Hi @sjrl, we have addressed all the review comments, please provide your feedback.
Thanks!

Comment thread integrations/ibm_db/LICENSE.txt Outdated
Comment thread integrations/ibm_db/CHANGELOG.md Outdated
Comment on lines +151 to +157
def test_write_documents(self, document_store: IBMDb2DocumentStore):
"""Test basic write with duplicate handling - default policy is NONE."""
doc = Document(content="test doc")
assert document_store.write_documents([doc]) == 1
# Default policy is NONE — a second write of the same doc raises DuplicateDocumentError
with pytest.raises(DuplicateDocumentError):
document_store.write_documents([doc])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

test_write_documents currently shadows WriteDocumentsTest.test_write_documents
from the mixin.

Could you rename it (e.g. test_write_documents_default_policy_none) so the mixin's version still runs?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've renamed the original test_write_documents to test_write_documents_default_policy_none as suggested, and added a separate test_write_documents override to satisfy the mixin's required hook - it just asserts that a basic write returns 1. I think now the mixin's version runs, and the duplicate-rejection behaviour (DuplicateDocumentError) is now tested independently in test_write_documents_default_policy_none.

database: str,
hostname: str,
username: Secret,
password: Secret,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It could be nice to set default values for these like

Suggested change
password: Secret,
username: Secret = Secret.from_env_var("DB2_USERNAME"),
password: Secret = Secret.from_env_var("DB2_PASSWORD"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Both username and password now default to Secret.from_env_var("DB2_USERNAME") and Secret.from_env_var("DB2_PASSWORD") respectively.

@sjrl

sjrl commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Hey @GeetikaChughIBM thanks for addressing all of the comments! I have a few minor ones left and then this is good to go!


Use inside a Haystack pipeline after a text embedder:

.. code-block:: python

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Our api docstrings don't support this type of markdown .. code-block:: python so could we switch to using the triple-backticks with the python tag?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay, switched to triple-backtick fenced code block (```python) in the docstring.

:param query_embedding: Dense float vector from an embedder component.
:param filters: Runtime filters, merged with constructor filters according to filter_policy.
:param top_k: Override the constructor top_k for this call.
:returns: A dictionary with key ``documents`` containing a list of matching :class:`Document` objects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
:returns: A dictionary with key ``documents`` containing a list of matching :class:`Document` objects.
:returns: A dictionary with key `documents` containing a list of matching :class:`Document` objects.

@GeetikaChughIBM GeetikaChughIBM Jul 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Done.. changed to documents in the :returns: docstring.

Comment on lines +167 to +169
Booleans are stored in JSON as ``true``/``false`` and read back by ``JSON_VALUE`` as the
lowercase strings ``'true'``/``'false'``. ibm_db would otherwise bind a Python bool as the
integer ``1``/``0``, so the comparison would never match. Convert it explicitly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please only use single backticks for inline code comments

Suggested change
Booleans are stored in JSON as ``true``/``false`` and read back by ``JSON_VALUE`` as the
lowercase strings ``'true'``/``'false'``. ibm_db would otherwise bind a Python bool as the
integer ``1``/``0``, so the comparison would never match. Convert it explicitly.
Booleans are stored in JSON as `true`/`false` and read back by `JSON_VALUE` as the
lowercase strings `'true'`/`'false'`. ibm_db would otherwise bind a Python bool as the
integer `1`/`0`, so the comparison would never match. Convert it explicitly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Done! now using single backticks for inline code comments

* fix: replace placeholder copyright with 'Copyright 2023-present deepset GmbH' in LICENSE.txt

* fix: remove CHANGELOG.md

* fix: rename test_write_documents to test_write_documents_default_policy_none to avoid shadowing mixin

* fix: add default Secret env var values for username and password params

* fix: replace code-block directive with triple-backtick markdown in docstring

* fix: use single backticks for 'documents' key in :returns: docstring

* fix: replace double backticks with single backticks in inline code comments in filters.py

* fix: add test_write_documents mixin override and separate test_write_documents_default_policy_none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants