sf-vector-sdk 0.2.2__py3-none-any.whl → 0.2.3__py3-none-any.whl
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.
- {sf_vector_sdk-0.2.2.dist-info → sf_vector_sdk-0.2.3.dist-info}/METADATA +1 -1
- {sf_vector_sdk-0.2.2.dist-info → sf_vector_sdk-0.2.3.dist-info}/RECORD +6 -6
- vector_sdk/__init__.py +1 -1
- vector_sdk/namespaces/embeddings.py +31 -57
- vector_sdk/namespaces/search.py +38 -60
- {sf_vector_sdk-0.2.2.dist-info → sf_vector_sdk-0.2.3.dist-info}/WHEEL +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
vector_sdk/__init__.py,sha256=
|
|
1
|
+
vector_sdk/__init__.py,sha256=JBhZJLh_1w0L0mo3pYcXxx2OZdwD4siglLH5a8TxcCs,6979
|
|
2
2
|
vector_sdk/client.py,sha256=NQFGHyR1aM0UToRFy6e9Xm_v6mk0opqzKN8UlHu97n0,17186
|
|
3
3
|
vector_sdk/content_types.py,sha256=krvFOR58iUZPfYlEVsk0sXD6_ANAFbxEBQGNpt1YPDU,7381
|
|
4
4
|
vector_sdk/types.py,sha256=rQgA2z3ls21vY-DRPZgfmm8gYFkWJk1dQaJI-nbc0no,25514
|
|
@@ -16,12 +16,12 @@ vector_sdk/hash/types.py,sha256=RHDM-ob9cOHPGMI7tXqiN_ZRowTPSc3GYHf8terrd8U,1983
|
|
|
16
16
|
vector_sdk/namespaces/__init__.py,sha256=S9dJfB39s2zjYOpFn9Fvf8bk7mLKcXk5aPatKOA-xO0,374
|
|
17
17
|
vector_sdk/namespaces/base.py,sha256=lioZBcd43mijnN0JwTMMEpQ6whiAjaueTDAAIZS1JM0,1156
|
|
18
18
|
vector_sdk/namespaces/db.py,sha256=a5sEHrfy1xAjRjyM9qfZxr3IznZVA8BnY5W1Hq5jr4I,7230
|
|
19
|
-
vector_sdk/namespaces/embeddings.py,sha256=
|
|
20
|
-
vector_sdk/namespaces/search.py,sha256=
|
|
19
|
+
vector_sdk/namespaces/embeddings.py,sha256=r0cbCZjj0jZ9oyBpm8lA2BjUYzi8bmunWwFsYxiXtJo,7704
|
|
20
|
+
vector_sdk/namespaces/search.py,sha256=8ruX0xp5vXD9tS8oXAu1vmF4aC25fNg4gDOtiR8aQ_0,7874
|
|
21
21
|
vector_sdk/structured/__init__.py,sha256=ZUhrH_l7bX5vA78DSKqDucWhfhYmkDX-W_MPzo5J9JU,1758
|
|
22
22
|
vector_sdk/structured/router.py,sha256=F3O1TYtbVFCPqVWCCYCt5QcRffX5WPlPQ7K3KlayooQ,5792
|
|
23
23
|
vector_sdk/structured/structured_embeddings.py,sha256=Z0enOHx4vdhxAs0sbk9B6XHtRjZSfeYbNbtbq9f8Hh8,37147
|
|
24
24
|
vector_sdk/structured/tool_config.py,sha256=YJp-S2_mwoODHWaWJHnGJRaKXuuqbbm2dYHTum2BuG4,8138
|
|
25
|
-
sf_vector_sdk-0.2.
|
|
26
|
-
sf_vector_sdk-0.2.
|
|
27
|
-
sf_vector_sdk-0.2.
|
|
25
|
+
sf_vector_sdk-0.2.3.dist-info/METADATA,sha256=MjgxnlU-zYwoIh6qyg68VBcT03aKBP73KJ-NA3hrVbs,15915
|
|
26
|
+
sf_vector_sdk-0.2.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
27
|
+
sf_vector_sdk-0.2.3.dist-info/RECORD,,
|
vector_sdk/__init__.py
CHANGED
|
@@ -154,26 +154,21 @@ class EmbeddingsNamespace(BaseNamespace):
|
|
|
154
154
|
Raises:
|
|
155
155
|
TimeoutError: If no result is received within the timeout
|
|
156
156
|
"""
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
f"No result received for {request_id} within {timeout}s"
|
|
173
|
-
)
|
|
174
|
-
finally:
|
|
175
|
-
pubsub.unsubscribe(channel)
|
|
176
|
-
pubsub.close()
|
|
157
|
+
list_key = f"embedding:response:{request_id}"
|
|
158
|
+
|
|
159
|
+
# BRPOP blocks until result is available or timeout
|
|
160
|
+
result = self._redis.brpop(list_key, timeout=timeout)
|
|
161
|
+
|
|
162
|
+
if result is None:
|
|
163
|
+
raise TimeoutError(
|
|
164
|
+
f"No result received for {request_id} within {timeout}s"
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
# result = (key, value)
|
|
168
|
+
data = json.loads(result[1])
|
|
169
|
+
# Cleanup the response list
|
|
170
|
+
self._redis.delete(list_key)
|
|
171
|
+
return EmbeddingResult.from_dict(data)
|
|
177
172
|
|
|
178
173
|
def create_and_wait(
|
|
179
174
|
self,
|
|
@@ -189,8 +184,8 @@ class EmbeddingsNamespace(BaseNamespace):
|
|
|
189
184
|
"""
|
|
190
185
|
Create embeddings and wait for the result.
|
|
191
186
|
|
|
192
|
-
|
|
193
|
-
|
|
187
|
+
Uses BRPOP for efficient blocking wait - no race condition since the result
|
|
188
|
+
is pushed to a list that persists until consumed.
|
|
194
189
|
|
|
195
190
|
Args:
|
|
196
191
|
texts: List of text inputs
|
|
@@ -205,43 +200,22 @@ class EmbeddingsNamespace(BaseNamespace):
|
|
|
205
200
|
Returns:
|
|
206
201
|
The embedding result
|
|
207
202
|
"""
|
|
208
|
-
# Generate request ID upfront so we can subscribe before submitting
|
|
209
203
|
request_id = str(uuid.uuid4())
|
|
210
|
-
channel = f"embedding:result:{request_id}"
|
|
211
|
-
|
|
212
|
-
# Subscribe BEFORE submitting to avoid race condition
|
|
213
|
-
pubsub = self._redis.pubsub()
|
|
214
|
-
pubsub.subscribe(channel)
|
|
215
|
-
|
|
216
|
-
try:
|
|
217
|
-
# Now submit the request (subscription is already active)
|
|
218
|
-
self.create(
|
|
219
|
-
texts=texts,
|
|
220
|
-
content_type=content_type,
|
|
221
|
-
priority=priority,
|
|
222
|
-
storage=storage,
|
|
223
|
-
metadata=metadata,
|
|
224
|
-
request_id=request_id,
|
|
225
|
-
embedding_model=embedding_model,
|
|
226
|
-
embedding_dimensions=embedding_dimensions,
|
|
227
|
-
)
|
|
228
204
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
pubsub.unsubscribe(channel)
|
|
244
|
-
pubsub.close()
|
|
205
|
+
# Submit the request first
|
|
206
|
+
self.create(
|
|
207
|
+
texts=texts,
|
|
208
|
+
content_type=content_type,
|
|
209
|
+
priority=priority,
|
|
210
|
+
storage=storage,
|
|
211
|
+
metadata=metadata,
|
|
212
|
+
request_id=request_id,
|
|
213
|
+
embedding_model=embedding_model,
|
|
214
|
+
embedding_dimensions=embedding_dimensions,
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
# Wait for result via BRPOP
|
|
218
|
+
return self.wait_for(request_id, timeout)
|
|
245
219
|
|
|
246
220
|
def get_queue_depth(self) -> dict[str, int]:
|
|
247
221
|
"""
|
vector_sdk/namespaces/search.py
CHANGED
|
@@ -151,26 +151,21 @@ class SearchNamespace(BaseNamespace):
|
|
|
151
151
|
Raises:
|
|
152
152
|
TimeoutError: If no result is received within the timeout
|
|
153
153
|
"""
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
f"No query result received for {request_id} within {timeout}s"
|
|
170
|
-
)
|
|
171
|
-
finally:
|
|
172
|
-
pubsub.unsubscribe(channel)
|
|
173
|
-
pubsub.close()
|
|
154
|
+
list_key = f"query:response:{request_id}"
|
|
155
|
+
|
|
156
|
+
# BRPOP blocks until result is available or timeout
|
|
157
|
+
result = self._redis.brpop(list_key, timeout=timeout)
|
|
158
|
+
|
|
159
|
+
if result is None:
|
|
160
|
+
raise TimeoutError(
|
|
161
|
+
f"No query result received for {request_id} within {timeout}s"
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
# result = (key, value)
|
|
165
|
+
data = json.loads(result[1])
|
|
166
|
+
# Cleanup the response list
|
|
167
|
+
self._redis.delete(list_key)
|
|
168
|
+
return QueryResult.from_dict(data)
|
|
174
169
|
|
|
175
170
|
def query_and_wait(
|
|
176
171
|
self,
|
|
@@ -193,8 +188,8 @@ class SearchNamespace(BaseNamespace):
|
|
|
193
188
|
"""
|
|
194
189
|
Submit a search query and wait for the result.
|
|
195
190
|
|
|
196
|
-
|
|
197
|
-
|
|
191
|
+
Uses BRPOP for efficient blocking wait - no race condition since the result
|
|
192
|
+
is pushed to a list that persists until consumed.
|
|
198
193
|
|
|
199
194
|
Args:
|
|
200
195
|
query_text: The text to search for
|
|
@@ -217,42 +212,25 @@ class SearchNamespace(BaseNamespace):
|
|
|
217
212
|
The query result
|
|
218
213
|
"""
|
|
219
214
|
request_id = str(uuid.uuid4())
|
|
220
|
-
channel = f"query:result:{request_id}"
|
|
221
|
-
|
|
222
|
-
pubsub = self._redis.pubsub()
|
|
223
|
-
pubsub.subscribe(channel)
|
|
224
|
-
|
|
225
|
-
try:
|
|
226
|
-
self.query(
|
|
227
|
-
query_text=query_text,
|
|
228
|
-
database=database,
|
|
229
|
-
top_k=top_k,
|
|
230
|
-
min_score=min_score,
|
|
231
|
-
filters=filters,
|
|
232
|
-
namespace=namespace,
|
|
233
|
-
collection=collection,
|
|
234
|
-
database_name=database_name,
|
|
235
|
-
include_vectors=include_vectors,
|
|
236
|
-
include_metadata=include_metadata,
|
|
237
|
-
embedding_model=embedding_model,
|
|
238
|
-
embedding_dimensions=embedding_dimensions,
|
|
239
|
-
priority=priority,
|
|
240
|
-
metadata=metadata,
|
|
241
|
-
request_id=request_id,
|
|
242
|
-
)
|
|
243
215
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
216
|
+
# Submit the request first
|
|
217
|
+
self.query(
|
|
218
|
+
query_text=query_text,
|
|
219
|
+
database=database,
|
|
220
|
+
top_k=top_k,
|
|
221
|
+
min_score=min_score,
|
|
222
|
+
filters=filters,
|
|
223
|
+
namespace=namespace,
|
|
224
|
+
collection=collection,
|
|
225
|
+
database_name=database_name,
|
|
226
|
+
include_vectors=include_vectors,
|
|
227
|
+
include_metadata=include_metadata,
|
|
228
|
+
embedding_model=embedding_model,
|
|
229
|
+
embedding_dimensions=embedding_dimensions,
|
|
230
|
+
priority=priority,
|
|
231
|
+
metadata=metadata,
|
|
232
|
+
request_id=request_id,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
# Wait for result via BRPOP
|
|
236
|
+
return self.wait_for(request_id, timeout)
|
|
File without changes
|