sie-qdrant 0.1.8__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.
- sie_qdrant-0.1.8/.gitignore +256 -0
- sie_qdrant-0.1.8/PKG-INFO +109 -0
- sie_qdrant-0.1.8/README.md +97 -0
- sie_qdrant-0.1.8/pyproject.toml +31 -0
- sie_qdrant-0.1.8/src/sie_qdrant/__init__.py +93 -0
- sie_qdrant-0.1.8/src/sie_qdrant/vectorizer.py +299 -0
- sie_qdrant-0.1.8/tests/__init__.py +0 -0
- sie_qdrant-0.1.8/tests/conftest.py +102 -0
- sie_qdrant-0.1.8/tests/test_integration.py +159 -0
- sie_qdrant-0.1.8/tests/test_vectorizer.py +278 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
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
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
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
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.venv
|
|
140
|
+
env/
|
|
141
|
+
venv/
|
|
142
|
+
ENV/
|
|
143
|
+
env.bak/
|
|
144
|
+
venv.bak/
|
|
145
|
+
|
|
146
|
+
# Spyder project settings
|
|
147
|
+
.spyderproject
|
|
148
|
+
.spyproject
|
|
149
|
+
|
|
150
|
+
# Rope project settings
|
|
151
|
+
.ropeproject
|
|
152
|
+
|
|
153
|
+
# mkdocs documentation
|
|
154
|
+
/site
|
|
155
|
+
|
|
156
|
+
# Pyre type checker
|
|
157
|
+
.pyre/
|
|
158
|
+
|
|
159
|
+
# pytype static type analyzer
|
|
160
|
+
.pytype/
|
|
161
|
+
|
|
162
|
+
# Cython debug symbols
|
|
163
|
+
cython_debug/
|
|
164
|
+
|
|
165
|
+
# PyCharm
|
|
166
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
167
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
168
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
169
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
170
|
+
#.idea/
|
|
171
|
+
|
|
172
|
+
# Abstra
|
|
173
|
+
# Abstra is an AI-powered process automation framework.
|
|
174
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
175
|
+
# Learn more at https://abstra.io/docs
|
|
176
|
+
.abstra/
|
|
177
|
+
|
|
178
|
+
# Visual Studio Code
|
|
179
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
180
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
181
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
182
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
183
|
+
# .vscode/
|
|
184
|
+
|
|
185
|
+
# Ruff stuff:
|
|
186
|
+
.ruff_cache/
|
|
187
|
+
|
|
188
|
+
# PyPI configuration file
|
|
189
|
+
.pypirc
|
|
190
|
+
|
|
191
|
+
# Cursor
|
|
192
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
193
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
194
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
195
|
+
.cursorignore
|
|
196
|
+
.cursorindexingignore
|
|
197
|
+
|
|
198
|
+
# vcscode
|
|
199
|
+
.vscode
|
|
200
|
+
|
|
201
|
+
# Marimo
|
|
202
|
+
marimo/_static/
|
|
203
|
+
marimo/_lsp/
|
|
204
|
+
__marimo__/
|
|
205
|
+
|
|
206
|
+
# SIE specific
|
|
207
|
+
# Model weights cache
|
|
208
|
+
.cache/
|
|
209
|
+
*.safetensors
|
|
210
|
+
*.bin
|
|
211
|
+
|
|
212
|
+
# Secrets (never commit)
|
|
213
|
+
*.pem
|
|
214
|
+
*.key
|
|
215
|
+
credentials.json
|
|
216
|
+
*-key.json
|
|
217
|
+
|
|
218
|
+
# Terraform
|
|
219
|
+
# Local .terraform directories (cached providers/modules)
|
|
220
|
+
**/.terraform/*
|
|
221
|
+
.terraform.lock*
|
|
222
|
+
# State files (contain sensitive data)
|
|
223
|
+
*.tfstate
|
|
224
|
+
*.tfstate.*
|
|
225
|
+
# Crash log files
|
|
226
|
+
crash.log
|
|
227
|
+
crash.*.log
|
|
228
|
+
# Override files (local developer overrides)
|
|
229
|
+
override.tf
|
|
230
|
+
override.tf.json
|
|
231
|
+
*_override.tf
|
|
232
|
+
*_override.tf.json
|
|
233
|
+
# tfvars files may contain secrets
|
|
234
|
+
*.tfvars
|
|
235
|
+
*.tfvars.json
|
|
236
|
+
# Keep .terraform.lock.hcl for reproducibility (provider versions)
|
|
237
|
+
|
|
238
|
+
# Node.js
|
|
239
|
+
node_modules/
|
|
240
|
+
|
|
241
|
+
# OS
|
|
242
|
+
.DS_Store
|
|
243
|
+
Thumbs.db
|
|
244
|
+
|
|
245
|
+
# VIM
|
|
246
|
+
*.swp
|
|
247
|
+
|
|
248
|
+
# Worktree metadata
|
|
249
|
+
.base-branch
|
|
250
|
+
|
|
251
|
+
# Temporary files
|
|
252
|
+
tmp/
|
|
253
|
+
.tmp/
|
|
254
|
+
.local/
|
|
255
|
+
|
|
256
|
+
.requirements-modal.txt
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sie-qdrant
|
|
3
|
+
Version: 0.1.8
|
|
4
|
+
Summary: SIE integration for Qdrant
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: qdrant-client>=1.7
|
|
7
|
+
Requires-Dist: sie-sdk>=0.1.0
|
|
8
|
+
Provides-Extra: dev
|
|
9
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
10
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# sie-qdrant
|
|
14
|
+
|
|
15
|
+
SIE integration for Qdrant.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install sie-qdrant
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Dense embeddings
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from qdrant_client import QdrantClient
|
|
27
|
+
from qdrant_client.models import Distance, VectorParams, PointStruct
|
|
28
|
+
from sie_qdrant import SIEVectorizer
|
|
29
|
+
|
|
30
|
+
vectorizer = SIEVectorizer(base_url="http://localhost:8080", model="BAAI/bge-m3")
|
|
31
|
+
|
|
32
|
+
qdrant = QdrantClient("http://localhost:6333")
|
|
33
|
+
qdrant.create_collection(
|
|
34
|
+
collection_name="documents",
|
|
35
|
+
vectors_config=VectorParams(size=1024, distance=Distance.COSINE),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
texts = ["first doc", "second doc"]
|
|
39
|
+
vectors = vectorizer.embed_documents(texts)
|
|
40
|
+
qdrant.upsert(
|
|
41
|
+
collection_name="documents",
|
|
42
|
+
points=[
|
|
43
|
+
PointStruct(id=i, vector=v, payload={"text": t})
|
|
44
|
+
for i, (t, v) in enumerate(zip(texts, vectors))
|
|
45
|
+
],
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
query_vec = vectorizer.embed_query("search text")
|
|
49
|
+
results = qdrant.query_points(
|
|
50
|
+
collection_name="documents", query=query_vec, limit=5
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Named vectors (dense + sparse)
|
|
55
|
+
|
|
56
|
+
SIE's multi-output encode produces dense and sparse vectors in one call.
|
|
57
|
+
Qdrant supports sparse vectors natively via `SparseVector(indices, values)`,
|
|
58
|
+
so no expansion to full vocabulary length is needed:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from qdrant_client import QdrantClient
|
|
62
|
+
from qdrant_client.models import (
|
|
63
|
+
Distance, VectorParams, PointStruct,
|
|
64
|
+
SparseVectorParams, SparseVector,
|
|
65
|
+
)
|
|
66
|
+
from sie_qdrant import SIENamedVectorizer
|
|
67
|
+
|
|
68
|
+
vectorizer = SIENamedVectorizer(
|
|
69
|
+
base_url="http://localhost:8080",
|
|
70
|
+
model="BAAI/bge-m3",
|
|
71
|
+
output_types=["dense", "sparse"],
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
qdrant = QdrantClient("http://localhost:6333")
|
|
75
|
+
qdrant.create_collection(
|
|
76
|
+
collection_name="documents",
|
|
77
|
+
vectors_config={"dense": VectorParams(size=1024, distance=Distance.COSINE)},
|
|
78
|
+
sparse_vectors_config={"sparse": SparseVectorParams()},
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
named = vectorizer.embed_documents(["hello world"])
|
|
82
|
+
qdrant.upsert(
|
|
83
|
+
collection_name="documents",
|
|
84
|
+
points=[
|
|
85
|
+
PointStruct(
|
|
86
|
+
id=0,
|
|
87
|
+
vector={
|
|
88
|
+
"dense": named[0]["dense"],
|
|
89
|
+
"sparse": SparseVector(**named[0]["sparse"]),
|
|
90
|
+
},
|
|
91
|
+
payload={"text": "hello world"},
|
|
92
|
+
)
|
|
93
|
+
],
|
|
94
|
+
)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Storage advantage:** Unlike integrations that expand sparse vectors to full
|
|
98
|
+
vocabulary length (~30K floats), Qdrant stores sparse vectors in their native
|
|
99
|
+
indices+values form, making hybrid search storage-efficient.
|
|
100
|
+
|
|
101
|
+
## Testing
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Unit tests (no server needed)
|
|
105
|
+
pytest
|
|
106
|
+
|
|
107
|
+
# Integration tests (requires SIE + Qdrant)
|
|
108
|
+
pytest -m integration
|
|
109
|
+
```
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# sie-qdrant
|
|
2
|
+
|
|
3
|
+
SIE integration for Qdrant.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install sie-qdrant
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Dense embeddings
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from qdrant_client import QdrantClient
|
|
15
|
+
from qdrant_client.models import Distance, VectorParams, PointStruct
|
|
16
|
+
from sie_qdrant import SIEVectorizer
|
|
17
|
+
|
|
18
|
+
vectorizer = SIEVectorizer(base_url="http://localhost:8080", model="BAAI/bge-m3")
|
|
19
|
+
|
|
20
|
+
qdrant = QdrantClient("http://localhost:6333")
|
|
21
|
+
qdrant.create_collection(
|
|
22
|
+
collection_name="documents",
|
|
23
|
+
vectors_config=VectorParams(size=1024, distance=Distance.COSINE),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
texts = ["first doc", "second doc"]
|
|
27
|
+
vectors = vectorizer.embed_documents(texts)
|
|
28
|
+
qdrant.upsert(
|
|
29
|
+
collection_name="documents",
|
|
30
|
+
points=[
|
|
31
|
+
PointStruct(id=i, vector=v, payload={"text": t})
|
|
32
|
+
for i, (t, v) in enumerate(zip(texts, vectors))
|
|
33
|
+
],
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
query_vec = vectorizer.embed_query("search text")
|
|
37
|
+
results = qdrant.query_points(
|
|
38
|
+
collection_name="documents", query=query_vec, limit=5
|
|
39
|
+
)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Named vectors (dense + sparse)
|
|
43
|
+
|
|
44
|
+
SIE's multi-output encode produces dense and sparse vectors in one call.
|
|
45
|
+
Qdrant supports sparse vectors natively via `SparseVector(indices, values)`,
|
|
46
|
+
so no expansion to full vocabulary length is needed:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from qdrant_client import QdrantClient
|
|
50
|
+
from qdrant_client.models import (
|
|
51
|
+
Distance, VectorParams, PointStruct,
|
|
52
|
+
SparseVectorParams, SparseVector,
|
|
53
|
+
)
|
|
54
|
+
from sie_qdrant import SIENamedVectorizer
|
|
55
|
+
|
|
56
|
+
vectorizer = SIENamedVectorizer(
|
|
57
|
+
base_url="http://localhost:8080",
|
|
58
|
+
model="BAAI/bge-m3",
|
|
59
|
+
output_types=["dense", "sparse"],
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
qdrant = QdrantClient("http://localhost:6333")
|
|
63
|
+
qdrant.create_collection(
|
|
64
|
+
collection_name="documents",
|
|
65
|
+
vectors_config={"dense": VectorParams(size=1024, distance=Distance.COSINE)},
|
|
66
|
+
sparse_vectors_config={"sparse": SparseVectorParams()},
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
named = vectorizer.embed_documents(["hello world"])
|
|
70
|
+
qdrant.upsert(
|
|
71
|
+
collection_name="documents",
|
|
72
|
+
points=[
|
|
73
|
+
PointStruct(
|
|
74
|
+
id=0,
|
|
75
|
+
vector={
|
|
76
|
+
"dense": named[0]["dense"],
|
|
77
|
+
"sparse": SparseVector(**named[0]["sparse"]),
|
|
78
|
+
},
|
|
79
|
+
payload={"text": "hello world"},
|
|
80
|
+
)
|
|
81
|
+
],
|
|
82
|
+
)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Storage advantage:** Unlike integrations that expand sparse vectors to full
|
|
86
|
+
vocabulary length (~30K floats), Qdrant stores sparse vectors in their native
|
|
87
|
+
indices+values form, making hybrid search storage-efficient.
|
|
88
|
+
|
|
89
|
+
## Testing
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Unit tests (no server needed)
|
|
93
|
+
pytest
|
|
94
|
+
|
|
95
|
+
# Integration tests (requires SIE + Qdrant)
|
|
96
|
+
pytest -m integration
|
|
97
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sie-qdrant"
|
|
3
|
+
version = "0.1.8"
|
|
4
|
+
description = "SIE integration for Qdrant"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"sie-sdk>=0.1.0",
|
|
9
|
+
"qdrant-client>=1.7",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[project.optional-dependencies]
|
|
13
|
+
dev = [
|
|
14
|
+
"pytest>=8.0",
|
|
15
|
+
"pytest-asyncio>=0.24",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[build-system]
|
|
19
|
+
requires = ["hatchling"]
|
|
20
|
+
build-backend = "hatchling.build"
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.targets.wheel]
|
|
23
|
+
packages = ["src/sie_qdrant"]
|
|
24
|
+
|
|
25
|
+
[tool.pytest.ini_options]
|
|
26
|
+
testpaths = ["tests"]
|
|
27
|
+
asyncio_mode = "auto"
|
|
28
|
+
markers = [
|
|
29
|
+
"integration: marks tests as integration tests (require running SIE server and Qdrant instance)",
|
|
30
|
+
]
|
|
31
|
+
addopts = "-v --tb=short -m 'not integration'"
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""SIE integration for Qdrant.
|
|
2
|
+
|
|
3
|
+
This package provides vectorizer helpers for Qdrant:
|
|
4
|
+
|
|
5
|
+
- SIEVectorizer: Compute dense embeddings via SIE for Qdrant collections
|
|
6
|
+
- SIENamedVectorizer: Compute multiple vector types (dense + sparse) for Qdrant named vectors
|
|
7
|
+
|
|
8
|
+
Qdrant supports both dense and sparse vectors natively. Dense vectors are
|
|
9
|
+
stored as ``list[float]``, and sparse vectors use ``SparseVector(indices, values)``
|
|
10
|
+
— no expansion to full vocabulary length is needed (unlike Weaviate).
|
|
11
|
+
|
|
12
|
+
Example usage (dense):
|
|
13
|
+
|
|
14
|
+
from qdrant_client import QdrantClient
|
|
15
|
+
from qdrant_client.models import Distance, VectorParams, PointStruct
|
|
16
|
+
from sie_qdrant import SIEVectorizer
|
|
17
|
+
|
|
18
|
+
vectorizer = SIEVectorizer(
|
|
19
|
+
base_url="http://localhost:8080",
|
|
20
|
+
model="BAAI/bge-m3",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
qdrant = QdrantClient("http://localhost:6333")
|
|
24
|
+
qdrant.create_collection(
|
|
25
|
+
collection_name="documents",
|
|
26
|
+
vectors_config=VectorParams(size=1024, distance=Distance.COSINE),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Embed and insert
|
|
30
|
+
texts = ["first doc", "second doc"]
|
|
31
|
+
vectors = vectorizer.embed_documents(texts)
|
|
32
|
+
qdrant.upsert(
|
|
33
|
+
collection_name="documents",
|
|
34
|
+
points=[
|
|
35
|
+
PointStruct(id=i, vector=v, payload={"text": t})
|
|
36
|
+
for i, (t, v) in enumerate(zip(texts, vectors))
|
|
37
|
+
],
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# Embed query and search
|
|
41
|
+
query_vector = vectorizer.embed_query("search text")
|
|
42
|
+
results = qdrant.query_points(
|
|
43
|
+
collection_name="documents",
|
|
44
|
+
query=query_vector,
|
|
45
|
+
limit=5,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
Example usage (named vectors for hybrid search):
|
|
49
|
+
|
|
50
|
+
from qdrant_client import QdrantClient
|
|
51
|
+
from qdrant_client.models import (
|
|
52
|
+
Distance, VectorParams, PointStruct,
|
|
53
|
+
SparseVectorParams, SparseVector,
|
|
54
|
+
)
|
|
55
|
+
from sie_qdrant import SIENamedVectorizer
|
|
56
|
+
|
|
57
|
+
vectorizer = SIENamedVectorizer(
|
|
58
|
+
base_url="http://localhost:8080",
|
|
59
|
+
model="BAAI/bge-m3",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
qdrant = QdrantClient("http://localhost:6333")
|
|
63
|
+
qdrant.create_collection(
|
|
64
|
+
collection_name="documents",
|
|
65
|
+
vectors_config={"dense": VectorParams(size=1024, distance=Distance.COSINE)},
|
|
66
|
+
sparse_vectors_config={"sparse": SparseVectorParams()},
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Embed with both dense and sparse in one SIE call
|
|
70
|
+
texts = ["first doc", "second doc"]
|
|
71
|
+
named = vectorizer.embed_documents(texts)
|
|
72
|
+
qdrant.upsert(
|
|
73
|
+
collection_name="documents",
|
|
74
|
+
points=[
|
|
75
|
+
PointStruct(
|
|
76
|
+
id=i,
|
|
77
|
+
vector={
|
|
78
|
+
"dense": v["dense"],
|
|
79
|
+
"sparse": SparseVector(**v["sparse"]),
|
|
80
|
+
},
|
|
81
|
+
payload={"text": t},
|
|
82
|
+
)
|
|
83
|
+
for i, (t, v) in enumerate(zip(texts, named))
|
|
84
|
+
],
|
|
85
|
+
)
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
from sie_qdrant.vectorizer import SIENamedVectorizer, SIEVectorizer
|
|
89
|
+
|
|
90
|
+
__all__ = [
|
|
91
|
+
"SIENamedVectorizer",
|
|
92
|
+
"SIEVectorizer",
|
|
93
|
+
]
|