Add MariaDB Vector DocumentStore integration - #3565
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Coverage report (tavily)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Implements MariaDBDocumentStore backed by MariaDB 11.7+ native VECTOR support with MHNSW indexing and full-text keyword search. - Full DocumentStore protocol: write_documents (FAIL/OVERWRITE/SKIP), filter_documents, delete_documents, count_documents - Vector similarity via VEC_DISTANCE_COSINE / VEC_DISTANCE_EUCLIDEAN - Full-text keyword search via MATCH ... AGAINST (NATURAL LANGUAGE MODE) - Haystack metadata filtering converted to JSON_EXTRACT SQL expressions - MariaDBEmbeddingRetriever and MariaDBKeywordRetriever with FilterPolicy - 80 tests: 68 unit + 12 integration (all verified against MariaDB 11.7) - GitHub Actions workflow with MariaDB 11.7 service container Closes deepset-ai#2340
- Make mariadb C extension import lazy so API reference builds without requiring libmariadb-dev in the docs environment - Fix Docker health check to use --su-mysql flag required by MariaDB 11.7 - Add mariadb (LGPL-2.1) to license compliance exclusion list
f71d1cd to
ff12b6a
Compare
- Add skip-install=true to default hatch env so docs build does not attempt to compile the mariadb C extension (libmariadb-dev not available in the API reference runner). The pydoc search_path already points to src/ so modules are importable without installation. - Switch service container health check from healthcheck.sh (unreliable in some MariaDB 11.7 images) to mysqladmin ping which is more robust.
…THCHECK The mariadb:11.7 Docker image ships with a HEALTHCHECK instruction. GitHub Actions automatically waits for it when no custom options override it. Custom health-cmd variants (healthcheck.sh, mysqladmin) were failing because the slim runner environment handles them differently.
anakin87
left a comment
There was a problem hiding this comment.
I took a first look and found some points to address and some others to discuss.
| # skip-install prevents hatch from installing the project (and thus the mariadb C extension) | ||
| # in the docs environment. The pydoc search_path points to src/ so modules are found directly. |
There was a problem hiding this comment.
mariadb==1.1.14 uses distutils internally, which is removed in Python 3.14 setuptools provides the shim to keep the test env working.
There was a problem hiding this comment.
This seems like a workaround. Can we use the solution suggested in https://mariadb.com/docs/connectors/mariadb-connector-python/faq#modulenotfounderror-no-module-named-packaging?
There was a problem hiding this comment.
Since users will need packaging to use mariadb, I'd add this package to main dependencies (not test). Does it make sense?
| blob_mime_type VARCHAR(255), | ||
| meta JSON, | ||
| FULLTEXT KEY content_ft_idx (content) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
There was a problem hiding this comment.
We should also set the distance function at table creation.
Also, let's make distance not changeable after table creation:
Declare DISTANCE explicitly. The default is euclidean, and a query using a different distance function than the one the index was built for cannot use the index, it falls back to a full table scan.
See https://mariadb.com/docs/server/reference/sql-structure/vectors/create-table-with-vectors
| {where_clause} | ||
| ORDER BY score DESC | ||
| LIMIT ? | ||
| """ |
There was a problem hiding this comment.
this might also return irrelevant documents if relevant ones are less than top_k
we should also apply matching on WHERE or filtering by score
|
Addressed all the straightforward review comments. The HNSW index design ( |
anakin87
left a comment
There was a problem hiding this comment.
There are still some comments to address.
Please request my review when they are fixed. In the meantime, ask questions if needed.
93e2728 to
8f91d92
Compare
|
ruff auto-detects |
|
I mistakently Referenced some PRs here , Well I have cleaned the mess the Code is opened for review |
| """ | ||
|
|
||
|
|
||
| class MariaDBDocumentStore(DocumentStore): |
There was a problem hiding this comment.
| class MariaDBDocumentStore(DocumentStore): | |
| class MariaDBDocumentStore: |
DocumentStore is a Python protocol. We generally don't inherit from it.
To stick to the protocol, only implementing the necessary methods is required (which you're already doing).
| meta JSON, | ||
| FULLTEXT KEY content_ft_idx (content), | ||
| VECTOR INDEX vec_idx (embedding) COMMENT 'MHNSW(distance={distance})' | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
There was a problem hiding this comment.
this does not seem to match the syntax in https://mariadb.com/docs/server/reference/sql-structure/vectors/create-table-with-vectors
| filters: dict[str, Any] | None = None, | ||
| top_k: int = 10, | ||
| score_threshold: float | None = None, | ||
| vector_function: str | None = None, |
There was a problem hiding this comment.
Searches using a different distance function will not be able to use a vector index
I'd simply not allow users to change the distance function at runtime, in other words by removing this parameter
| user: Secret | str = Secret.from_env_var("MARIADB_USER"), | ||
| password: Secret | str = Secret.from_env_var("MARIADB_PASSWORD"), |
There was a problem hiding this comment.
| user: Secret | str = Secret.from_env_var("MARIADB_USER"), | |
| password: Secret | str = Secret.from_env_var("MARIADB_PASSWORD"), | |
| user: Secret = Secret.from_env_var("MARIADB_USER"), | |
| password: Secret = Secret.from_env_var("MARIADB_PASSWORD"), |
We don't want to support strings
| # --------------------------------------------------------------------------- | ||
| # Helper: build a store with a mocked DB connection | ||
| # --------------------------------------------------------------------------- |
There was a problem hiding this comment.
| # --------------------------------------------------------------------------- | |
| # Helper: build a store with a mocked DB connection | |
| # --------------------------------------------------------------------------- |
Remove all these separation comments
anakin87
left a comment
There was a problem hiding this comment.
There are still a few rough edges to address in this PR, including some points that were left unresolved from the previous review.
Since this is a new integration, I'd like to see a more thorough pass: try it yourself, refine the implementation, and make sure to address the existing feedback.
Otherwise, I may need to deprioritize further review.
|
Hi @anakin87 , I've addressed all of your review comments:
I also verified everything against a real MariaDB 11.7 Docker instance all 120 tests are passing (65 unit + 55 integration). |
Summary
Part of #2340
Implements a complete MariaDB document store integration using MariaDB 11.7+ native
VECTORsupport.MariaDBDocumentStorefull DocumentStore protocol (write_documents,filter_documents,delete_documents,count_documents)VEC_DISTANCE_COSINE/VEC_DISTANCE_EUCLIDEANwithMHNSWindexingMATCH ... AGAINST (IN NATURAL LANGUAGE MODE)on aFULLTEXTindexJSON_UNQUOTE(JSON_EXTRACT(...))SQL expressions with parameterized queriesMariaDBEmbeddingRetrieverandMariaDBKeywordRetrieverwithFilterPolicysupportDuplicatePolicysupport:FAIL(INSERT),OVERWRITE(upsert viaON DUPLICATE KEY UPDATE),SKIP(INSERT IGNORE)Tests
80 tests total all passing:
CI
Added
.github/workflows/mariadb.ymlwith a MariaDB 11.7 service container, matching the pattern used bypgvector.How to run locally