mariadb-haystack 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,146 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ volumes/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ .python-version
87
+
88
+ # pipenv
89
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
90
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
91
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
92
+ # install all needed dependencies.
93
+ #Pipfile.lock
94
+
95
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
96
+ __pypackages__/
97
+
98
+ # Celery stuff
99
+ celerybeat-schedule
100
+ celerybeat.pid
101
+
102
+ # SageMath parsed files
103
+ *.sage.py
104
+
105
+ # Environments
106
+ .env
107
+ .venv
108
+ env/
109
+ venv/
110
+ ENV/
111
+ env.bak/
112
+ venv.bak/
113
+
114
+ # Spyder project settings
115
+ .spyderproject
116
+ .spyproject
117
+
118
+ # Rope project settings
119
+ .ropeproject
120
+
121
+ # mkdocs documentation
122
+ /site
123
+
124
+ # mypy
125
+ .mypy_cache/
126
+ .dmypy.json
127
+ dmypy.json
128
+
129
+ # Pyre type checker
130
+ .pyre/
131
+
132
+ # IDEs
133
+ .vscode
134
+
135
+ # Docs generation artifacts
136
+ _readme_*.md
137
+ .idea
138
+
139
+ # macOS
140
+ .DS_Store
141
+
142
+ # http cache (requests-cache)
143
+ **/http_cache.sqlite
144
+
145
+ # ruff
146
+ .ruff_cache
@@ -0,0 +1,73 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent passes licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+
37
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
38
+
39
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+
41
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
42
+
43
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
56
+
57
+ APPENDIX: How to apply the Apache License to your work.
58
+
59
+ To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
60
+
61
+ Copyright [yyyy] [name of copyright owner]
62
+
63
+ Licensed under the Apache License, Version 2.0 (the "License");
64
+ you may not use this file except in compliance with the License.
65
+ You may obtain a copy of the License at
66
+
67
+ http://www.apache.org/licenses/LICENSE-2.0
68
+
69
+ Unless required by applicable law or agreed to in writing, software
70
+ distributed under the License is distributed on an "AS IS" BASIS,
71
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72
+ See the License for the specific language governing permissions and
73
+ limitations under the License.
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.5
2
+ Name: mariadb-haystack
3
+ Version: 0.0.1
4
+ Summary: An integration of MariaDB 11.7+ (native VECTOR support) with Haystack
5
+ Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations
6
+ Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/mariadb/README.md
7
+ Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
8
+ Author-email: deepset GmbH <info@deepset.ai>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE.txt
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: Implementation :: CPython
20
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: haystack-ai>=2.28.0
23
+ Requires-Dist: mariadb>=1.1.6
24
+ Description-Content-Type: text/markdown
25
+
26
+ # mariadb-haystack
27
+
28
+ [![PyPI - Version](https://img.shields.io/pypi/v/mariadb-haystack.svg)](https://pypi.org/project/mariadb-haystack)
29
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mariadb-haystack.svg)](https://pypi.org/project/mariadb-haystack)
30
+
31
+ - [Integration page](https://haystack.deepset.ai/integrations/mariadb-documentstore)
32
+ - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/mariadb/CHANGELOG.md)
33
+
34
+ ---
35
+
36
+ ## Contributing
37
+
38
+ Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
39
+
40
+ The `mariadb` connector is a C extension built from source, so it needs the MariaDB Connector/C system library
41
+ (`mariadb_config`): `sudo apt-get install -y libmariadb-dev` on Ubuntu, or `brew install mariadb-connector-c`
42
+ on macOS.
43
+
44
+ To run integration tests locally, you need a MariaDB 11.7+ instance running.
45
+ You can start one using Docker:
46
+
47
+ ```console
48
+ docker run -d --name mariadb-haystack -e MARIADB_ROOT_PASSWORD=password -e MARIADB_DATABASE=haystack -p 3306:3306 mariadb:11.7
49
+ ```
@@ -0,0 +1,24 @@
1
+ # mariadb-haystack
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/mariadb-haystack.svg)](https://pypi.org/project/mariadb-haystack)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mariadb-haystack.svg)](https://pypi.org/project/mariadb-haystack)
5
+
6
+ - [Integration page](https://haystack.deepset.ai/integrations/mariadb-documentstore)
7
+ - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/mariadb/CHANGELOG.md)
8
+
9
+ ---
10
+
11
+ ## Contributing
12
+
13
+ Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
14
+
15
+ The `mariadb` connector is a C extension built from source, so it needs the MariaDB Connector/C system library
16
+ (`mariadb_config`): `sudo apt-get install -y libmariadb-dev` on Ubuntu, or `brew install mariadb-connector-c`
17
+ on macOS.
18
+
19
+ To run integration tests locally, you need a MariaDB 11.7+ instance running.
20
+ You can start one using Docker:
21
+
22
+ ```console
23
+ docker run -d --name mariadb-haystack -e MARIADB_ROOT_PASSWORD=password -e MARIADB_DATABASE=haystack -p 3306:3306 mariadb:11.7
24
+ ```
@@ -0,0 +1,15 @@
1
+ loaders:
2
+ - modules:
3
+ - haystack_integrations.components.retrievers.mariadb.embedding_retriever
4
+ - haystack_integrations.components.retrievers.mariadb.keyword_retriever
5
+ - haystack_integrations.document_stores.mariadb.document_store
6
+ search_path: [../src]
7
+ processors:
8
+ - type: filter
9
+ documented_only: true
10
+ skip_empty_modules: true
11
+ renderer:
12
+ description: MariaDB integration for Haystack
13
+ id: integrations-mariadb
14
+ filename: mariadb.md
15
+ title: MariaDB
@@ -0,0 +1,168 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "mariadb-haystack"
7
+ dynamic = ["version"]
8
+ description = "An integration of MariaDB 11.7+ (native VECTOR support) with Haystack"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "Apache-2.0"
12
+ keywords = []
13
+ authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
14
+ classifiers = [
15
+ "License :: OSI Approved :: Apache Software License",
16
+ "Development Status :: 4 - Beta",
17
+ "Programming Language :: Python",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Programming Language :: Python :: Implementation :: CPython",
24
+ "Programming Language :: Python :: Implementation :: PyPy",
25
+ ]
26
+ dependencies = [
27
+ "haystack-ai>=2.28.0",
28
+ "mariadb>=1.1.6",
29
+ ]
30
+
31
+ [project.urls]
32
+ Source = "https://github.com/deepset-ai/haystack-core-integrations"
33
+ Documentation = "https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/mariadb/README.md"
34
+ Issues = "https://github.com/deepset-ai/haystack-core-integrations/issues"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/haystack_integrations"]
38
+
39
+ [tool.hatch.version]
40
+ source = "vcs"
41
+ tag-pattern = 'integrations\/mariadb-v(?P<version>.*)'
42
+
43
+ [tool.hatch.version.raw-options]
44
+ root = "../.."
45
+ git_describe_command = 'git describe --tags --match="integrations/mariadb-v[0-9]*"'
46
+
47
+ [tool.hatch.envs.default]
48
+ installer = "uv"
49
+ # Don't install the project here: at build time, it would need the MariaDB system library, which is not available
50
+ # in the API reference workflow. haystack-pydoc-tools and ruff just need to parse the source, so it's OK.
51
+ skip-install = true
52
+ dependencies = ["haystack-pydoc-tools", "ruff"]
53
+
54
+ [tool.hatch.envs.default.scripts]
55
+ docs = ["haystack-pydoc pydoc/config_docusaurus.yml"]
56
+ fmt = "ruff check --fix {args}; ruff format {args}"
57
+ fmt-check = "ruff check {args} && ruff format --check {args}"
58
+
59
+ [tool.hatch.envs.test]
60
+ skip-install = false
61
+ dependencies = [
62
+ "pytest",
63
+ "pytest-asyncio",
64
+ "pytest-cov",
65
+ "pytest-rerunfailures",
66
+ "mypy",
67
+ "pip",
68
+ ]
69
+
70
+ [tool.hatch.envs.test.scripts]
71
+ unit = 'pytest -m "not integration" {args:tests}'
72
+ integration = 'pytest -m "integration" {args:tests}'
73
+ all = 'pytest {args:tests}'
74
+ unit-cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x -m "not integration" {args:tests}'
75
+ integration-cov-append-retry = 'pytest --cov=haystack_integrations --cov-append --reruns 3 --reruns-delay 30 -x -m "integration" {args:tests}'
76
+
77
+ types = "mypy -p haystack_integrations.document_stores.mariadb -p haystack_integrations.components.retrievers.mariadb {args}"
78
+
79
+ [tool.mypy]
80
+ install_types = true
81
+ non_interactive = true
82
+ check_untyped_defs = true
83
+ disallow_incomplete_defs = true
84
+
85
+ [[tool.mypy.overrides]]
86
+ module = [
87
+ "mariadb.*",
88
+ ]
89
+ ignore_missing_imports = true
90
+
91
+ [tool.ruff]
92
+ line-length = 120
93
+
94
+ [tool.ruff.lint]
95
+ select = [
96
+ "A",
97
+ "ANN",
98
+ "ARG",
99
+ "B",
100
+ "C",
101
+ "D102",
102
+ "D103",
103
+ "D205",
104
+ "D209",
105
+ "D213",
106
+ "D417",
107
+ "D419",
108
+ "DTZ",
109
+ "E",
110
+ "EM",
111
+ "F",
112
+ "FBT",
113
+ "I",
114
+ "ICN",
115
+ "ISC",
116
+ "N",
117
+ "PLC",
118
+ "PLE",
119
+ "PLR",
120
+ "PLW",
121
+ "Q",
122
+ "RUF",
123
+ "S",
124
+ "T",
125
+ "TID",
126
+ "UP",
127
+ "W",
128
+ "YTT",
129
+ ]
130
+ ignore = [
131
+ "B027",
132
+ "ANN401",
133
+ "FBT003",
134
+ "S105",
135
+ "S106",
136
+ "S107",
137
+ "C901",
138
+ "PLR0911",
139
+ "PLR0912",
140
+ "PLR0913",
141
+ "PLR0915",
142
+ "B008",
143
+ "S101",
144
+ ]
145
+
146
+ [tool.ruff.lint.isort]
147
+ known-first-party = ["haystack_integrations"]
148
+
149
+ [tool.ruff.lint.flake8-tidy-imports]
150
+ ban-relative-imports = "parents"
151
+
152
+ [tool.ruff.lint.per-file-ignores]
153
+ "tests/**/*" = ["D", "PLR2004", "S101", "TID252", "ANN"]
154
+ "examples/**/*" = ["D", "T201"]
155
+
156
+ [tool.coverage.run]
157
+ source = ["haystack_integrations"]
158
+ branch = true
159
+ relative_files = true
160
+ parallel = false
161
+
162
+ [tool.coverage.report]
163
+ omit = ["*/tests/*", "*/__init__.py"]
164
+ show_missing = true
165
+ exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
166
+
167
+ [tool.pytest.ini_options]
168
+ markers = ["integration: integration tests"]
@@ -0,0 +1,8 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from haystack_integrations.components.retrievers.mariadb.embedding_retriever import MariaDBEmbeddingRetriever
6
+ from haystack_integrations.components.retrievers.mariadb.keyword_retriever import MariaDBKeywordRetriever
7
+
8
+ __all__ = ["MariaDBEmbeddingRetriever", "MariaDBKeywordRetriever"]
@@ -0,0 +1,112 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from typing import Any
6
+
7
+ from haystack import component, default_from_dict, default_to_dict
8
+ from haystack.dataclasses import Document
9
+ from haystack.document_stores.types import FilterPolicy
10
+ from haystack.document_stores.types.filter_policy import apply_filter_policy
11
+
12
+ from haystack_integrations.document_stores.mariadb import MariaDBDocumentStore
13
+
14
+
15
+ @component
16
+ class MariaDBEmbeddingRetriever:
17
+ """
18
+ Retrieves documents from `MariaDBDocumentStore` using vector similarity search.
19
+
20
+ Uses MariaDB's native `VEC_DISTANCE_COSINE` or `VEC_DISTANCE_EUCLIDEAN` functions
21
+ with MHNSW indexing for efficient approximate nearest-neighbour search.
22
+
23
+ ### Usage example
24
+
25
+ ```python
26
+ from haystack_integrations.document_stores.mariadb import MariaDBDocumentStore
27
+ from haystack_integrations.components.retrievers.mariadb import MariaDBEmbeddingRetriever
28
+
29
+ store = MariaDBDocumentStore(host="localhost", database="haystack", embedding_dimension=768)
30
+ retriever = MariaDBEmbeddingRetriever(document_store=store, top_k=5)
31
+ result = retriever.run(query_embedding=[0.1] * 768)
32
+ documents = result["documents"]
33
+ ```
34
+ """
35
+
36
+ def __init__(
37
+ self,
38
+ *,
39
+ document_store: MariaDBDocumentStore,
40
+ filters: dict[str, Any] | None = None,
41
+ top_k: int = 10,
42
+ score_threshold: float | None = None,
43
+ filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
44
+ ) -> None:
45
+ """
46
+ Initialize the MariaDBEmbeddingRetriever.
47
+
48
+ :param document_store: A `MariaDBDocumentStore` instance.
49
+ :param filters: Default Haystack metadata filters applied to every query.
50
+ :param top_k: Maximum number of documents to return.
51
+ :param score_threshold: Minimum score to include a document. Documents below this score are excluded.
52
+ :param filter_policy: How runtime filters interact with init-time filters.
53
+ :raises ValueError: If `document_store` is not a `MariaDBDocumentStore`.
54
+ """
55
+ if not isinstance(document_store, MariaDBDocumentStore):
56
+ msg = "document_store must be an instance of MariaDBDocumentStore"
57
+ raise ValueError(msg)
58
+
59
+ self.document_store = document_store
60
+ self.filters = filters or {}
61
+ self.top_k = top_k
62
+ self.score_threshold = score_threshold
63
+ self.filter_policy = (
64
+ filter_policy if isinstance(filter_policy, FilterPolicy) else FilterPolicy.from_str(filter_policy)
65
+ )
66
+
67
+ def to_dict(self) -> dict[str, Any]:
68
+ """Serialize the component to a dictionary."""
69
+ return default_to_dict(
70
+ self,
71
+ filters=self.filters,
72
+ top_k=self.top_k,
73
+ score_threshold=self.score_threshold,
74
+ filter_policy=self.filter_policy.value,
75
+ document_store=self.document_store.to_dict(),
76
+ )
77
+
78
+ @classmethod
79
+ def from_dict(cls, data: dict[str, Any]) -> "MariaDBEmbeddingRetriever":
80
+ """Deserialize the component from a dictionary."""
81
+ doc_store_params = data["init_parameters"]["document_store"]
82
+ data["init_parameters"]["document_store"] = MariaDBDocumentStore.from_dict(doc_store_params)
83
+ if filter_policy := data["init_parameters"].get("filter_policy"):
84
+ data["init_parameters"]["filter_policy"] = FilterPolicy.from_str(filter_policy)
85
+ return default_from_dict(cls, data)
86
+
87
+ @component.output_types(documents=list[Document])
88
+ def run(
89
+ self,
90
+ query_embedding: list[float],
91
+ filters: dict[str, Any] | None = None,
92
+ top_k: int | None = None,
93
+ score_threshold: float | None = None,
94
+ ) -> dict[str, list[Document]]:
95
+ """
96
+ Retrieve documents similar to the query embedding.
97
+
98
+ :param query_embedding: The query vector.
99
+ :param filters: Runtime filters merged with init-time filters per `filter_policy`.
100
+ :param top_k: Override the retriever's `top_k`.
101
+ :param score_threshold: Override the retriever's `score_threshold`.
102
+ :returns: Dictionary with `"documents"` key containing the ranked results.
103
+ """
104
+ filters = apply_filter_policy(self.filter_policy, self.filters, filters)
105
+ return {
106
+ "documents": self.document_store._embedding_retrieval(
107
+ query_embedding=query_embedding,
108
+ filters=filters,
109
+ top_k=top_k or self.top_k,
110
+ score_threshold=score_threshold if score_threshold is not None else self.score_threshold,
111
+ )
112
+ }