llama-index-vector-stores-opensearch 0.1.9__py3-none-any.whl → 0.1.11__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.
Potentially problematic release.
This version of llama-index-vector-stores-opensearch might be problematic. Click here for more details.
- llama_index/vector_stores/opensearch/base.py +36 -10
- {llama_index_vector_stores_opensearch-0.1.9.dist-info → llama_index_vector_stores_opensearch-0.1.11.dist-info}/METADATA +2 -1
- llama_index_vector_stores_opensearch-0.1.11.dist-info/RECORD +5 -0
- {llama_index_vector_stores_opensearch-0.1.9.dist-info → llama_index_vector_stores_opensearch-0.1.11.dist-info}/WHEEL +1 -1
- llama_index_vector_stores_opensearch-0.1.9.dist-info/RECORD +0 -5
|
@@ -239,12 +239,12 @@ class OpensearchVectorClient:
|
|
|
239
239
|
Returns:
|
|
240
240
|
Up to k docs closest to query_embedding
|
|
241
241
|
"""
|
|
242
|
-
|
|
242
|
+
pre_filter = self._parse_filters(filters)
|
|
243
|
+
if not pre_filter:
|
|
243
244
|
search_query = self._default_approximate_search_query(
|
|
244
245
|
query_embedding, k, vector_field=embedding_field
|
|
245
246
|
)
|
|
246
247
|
else:
|
|
247
|
-
pre_filter = self._parse_filters(filters)
|
|
248
248
|
# https://opensearch.org/docs/latest/search-plugins/knn/painless-functions/
|
|
249
249
|
search_query = self._default_painless_scripting_query(
|
|
250
250
|
query_embedding,
|
|
@@ -265,17 +265,34 @@ class OpensearchVectorClient:
|
|
|
265
265
|
k: int,
|
|
266
266
|
filters: Optional[MetadataFilters] = None,
|
|
267
267
|
) -> Dict:
|
|
268
|
-
knn_query = self._knn_search_query(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
268
|
+
knn_query = self._knn_search_query(embedding_field, query_embedding, k, filters)
|
|
269
|
+
lexical_query = self._lexical_search_query(text_field, query_str, k, filters)
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
"size": k,
|
|
273
|
+
"query": {
|
|
274
|
+
"hybrid": {"queries": [lexical_query["query"], knn_query["query"]]}
|
|
275
|
+
},
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
def _lexical_search_query(
|
|
279
|
+
self,
|
|
280
|
+
text_field: str,
|
|
281
|
+
query_str: str,
|
|
282
|
+
k: int,
|
|
283
|
+
filters: Optional[MetadataFilters] = None,
|
|
284
|
+
) -> Dict:
|
|
285
|
+
lexical_query = {
|
|
286
|
+
"bool": {"must": {"match": {text_field: {"query": query_str}}}}
|
|
287
|
+
}
|
|
272
288
|
|
|
273
289
|
parsed_filters = self._parse_filters(filters)
|
|
274
290
|
if len(parsed_filters) > 0:
|
|
275
|
-
lexical_query["filter"] = parsed_filters
|
|
291
|
+
lexical_query["bool"]["filter"] = parsed_filters
|
|
292
|
+
|
|
276
293
|
return {
|
|
277
294
|
"size": k,
|
|
278
|
-
"query":
|
|
295
|
+
"query": lexical_query,
|
|
279
296
|
}
|
|
280
297
|
|
|
281
298
|
def __get_painless_scripting_source(
|
|
@@ -388,17 +405,25 @@ class OpensearchVectorClient:
|
|
|
388
405
|
)
|
|
389
406
|
params = {
|
|
390
407
|
"search_pipeline": self._search_pipeline,
|
|
391
|
-
"_source_excludes": ["embedding"],
|
|
392
408
|
}
|
|
409
|
+
elif query_mode == VectorStoreQueryMode.TEXT_SEARCH:
|
|
410
|
+
search_query = self._lexical_search_query(
|
|
411
|
+
self._text_field, query_str, k, filters=filters
|
|
412
|
+
)
|
|
413
|
+
params = None
|
|
393
414
|
else:
|
|
394
415
|
search_query = self._knn_search_query(
|
|
395
416
|
self._embedding_field, query_embedding, k, filters=filters
|
|
396
417
|
)
|
|
397
|
-
params =
|
|
418
|
+
params = None
|
|
398
419
|
|
|
399
420
|
res = await self._os_client.search(
|
|
400
421
|
index=self._index, body=search_query, params=params
|
|
401
422
|
)
|
|
423
|
+
|
|
424
|
+
return self._to_query_result(res)
|
|
425
|
+
|
|
426
|
+
def _to_query_result(self, res) -> VectorStoreQueryResult:
|
|
402
427
|
nodes = []
|
|
403
428
|
ids = []
|
|
404
429
|
scores = []
|
|
@@ -433,6 +458,7 @@ class OpensearchVectorClient:
|
|
|
433
458
|
ids.append(node_id)
|
|
434
459
|
nodes.append(node)
|
|
435
460
|
scores.append(hit["_score"])
|
|
461
|
+
|
|
436
462
|
return VectorStoreQueryResult(nodes=nodes, ids=ids, similarities=scores)
|
|
437
463
|
|
|
438
464
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: llama-index-vector-stores-opensearch
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.11
|
|
4
4
|
Summary: llama-index vector_stores opensearch integration
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Your Name
|
|
@@ -11,6 +11,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.9
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
15
|
Requires-Dist: llama-index-core (>=0.10.1,<0.11.0)
|
|
15
16
|
Requires-Dist: opensearch-py[async] (>=2.4.2,<3.0.0)
|
|
16
17
|
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
llama_index/vector_stores/opensearch/__init__.py,sha256=U1_XAkZb6zcskOk4s10NB8Tjs9AZRGdRQLzOGpbWdBA,176
|
|
2
|
+
llama_index/vector_stores/opensearch/base.py,sha256=bHE7FV-CLU-x_ChG9CdoE4WzT1YkkZyIg23PYB7Eg30,19780
|
|
3
|
+
llama_index_vector_stores_opensearch-0.1.11.dist-info/METADATA,sha256=JrqjHpIkrncELU0t2pNIKbbYaAahVnFP8r9Tz0LeYrE,729
|
|
4
|
+
llama_index_vector_stores_opensearch-0.1.11.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
5
|
+
llama_index_vector_stores_opensearch-0.1.11.dist-info/RECORD,,
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
llama_index/vector_stores/opensearch/__init__.py,sha256=U1_XAkZb6zcskOk4s10NB8Tjs9AZRGdRQLzOGpbWdBA,176
|
|
2
|
-
llama_index/vector_stores/opensearch/base.py,sha256=KoDUhRZXknBXBiODovw_PgvtFFAhbdkT0hU9NpMYl4o,19141
|
|
3
|
-
llama_index_vector_stores_opensearch-0.1.9.dist-info/METADATA,sha256=r6OTnDiVcC9eU-mzDS_dxHjRd9Q7GM2mHNF7-oFuxOc,677
|
|
4
|
-
llama_index_vector_stores_opensearch-0.1.9.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
|
|
5
|
-
llama_index_vector_stores_opensearch-0.1.9.dist-info/RECORD,,
|