gllm-datastore-binary 0.5.45__cp311-cp311-macosx_13_0_arm64.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 gllm-datastore-binary might be problematic. Click here for more details.
- gllm_datastore/__init__.pyi +0 -0
- gllm_datastore/cache/__init__.pyi +4 -0
- gllm_datastore/cache/base.pyi +84 -0
- gllm_datastore/cache/cache.pyi +137 -0
- gllm_datastore/cache/hybrid_cache/__init__.pyi +5 -0
- gllm_datastore/cache/hybrid_cache/file_system_hybrid_cache.pyi +50 -0
- gllm_datastore/cache/hybrid_cache/hybrid_cache.pyi +115 -0
- gllm_datastore/cache/hybrid_cache/in_memory_hybrid_cache.pyi +29 -0
- gllm_datastore/cache/hybrid_cache/key_matcher/__init__.pyi +5 -0
- gllm_datastore/cache/hybrid_cache/key_matcher/exact_key_matcher.pyi +44 -0
- gllm_datastore/cache/hybrid_cache/key_matcher/fuzzy_key_matcher.pyi +70 -0
- gllm_datastore/cache/hybrid_cache/key_matcher/key_matcher.pyi +60 -0
- gllm_datastore/cache/hybrid_cache/key_matcher/semantic_key_matcher.pyi +93 -0
- gllm_datastore/cache/hybrid_cache/redis_hybrid_cache.pyi +34 -0
- gllm_datastore/cache/hybrid_cache/utils.pyi +36 -0
- gllm_datastore/cache/utils.pyi +34 -0
- gllm_datastore/cache/vector_cache/__init__.pyi +0 -0
- gllm_datastore/cache/vector_cache/eviction_manager/__init__.pyi +0 -0
- gllm_datastore/cache/vector_cache/eviction_manager/asyncio_eviction_manager.pyi +48 -0
- gllm_datastore/cache/vector_cache/eviction_manager/eviction_manager.pyi +38 -0
- gllm_datastore/cache/vector_cache/eviction_strategy/__init__.pyi +0 -0
- gllm_datastore/cache/vector_cache/eviction_strategy/eviction_strategy.pyi +34 -0
- gllm_datastore/cache/vector_cache/eviction_strategy/ttl_eviction_strategy.pyi +34 -0
- gllm_datastore/cache/vector_cache/vector_cache.pyi +99 -0
- gllm_datastore/constants.pyi +66 -0
- gllm_datastore/core/__init__.pyi +7 -0
- gllm_datastore/core/capabilities/__init__.pyi +5 -0
- gllm_datastore/core/capabilities/fulltext_capability.pyi +73 -0
- gllm_datastore/core/capabilities/graph_capability.pyi +70 -0
- gllm_datastore/core/capabilities/vector_capability.pyi +90 -0
- gllm_datastore/core/filters/__init__.pyi +4 -0
- gllm_datastore/core/filters/filter.pyi +340 -0
- gllm_datastore/core/filters/schema.pyi +149 -0
- gllm_datastore/data_store/__init__.pyi +7 -0
- gllm_datastore/data_store/base.pyi +138 -0
- gllm_datastore/data_store/chroma/__init__.pyi +4 -0
- gllm_datastore/data_store/chroma/_chroma_import.pyi +13 -0
- gllm_datastore/data_store/chroma/data_store.pyi +202 -0
- gllm_datastore/data_store/chroma/fulltext.pyi +134 -0
- gllm_datastore/data_store/chroma/query.pyi +266 -0
- gllm_datastore/data_store/chroma/query_translator.pyi +41 -0
- gllm_datastore/data_store/chroma/vector.pyi +197 -0
- gllm_datastore/data_store/elasticsearch/__init__.pyi +5 -0
- gllm_datastore/data_store/elasticsearch/data_store.pyi +119 -0
- gllm_datastore/data_store/elasticsearch/fulltext.pyi +237 -0
- gllm_datastore/data_store/elasticsearch/query.pyi +114 -0
- gllm_datastore/data_store/elasticsearch/vector.pyi +179 -0
- gllm_datastore/data_store/exceptions.pyi +35 -0
- gllm_datastore/data_store/in_memory/__init__.pyi +5 -0
- gllm_datastore/data_store/in_memory/data_store.pyi +71 -0
- gllm_datastore/data_store/in_memory/fulltext.pyi +131 -0
- gllm_datastore/data_store/in_memory/query.pyi +175 -0
- gllm_datastore/data_store/in_memory/vector.pyi +174 -0
- gllm_datastore/data_store/redis/__init__.pyi +5 -0
- gllm_datastore/data_store/redis/data_store.pyi +154 -0
- gllm_datastore/data_store/redis/fulltext.pyi +128 -0
- gllm_datastore/data_store/redis/query.pyi +428 -0
- gllm_datastore/data_store/redis/query_translator.pyi +37 -0
- gllm_datastore/data_store/redis/vector.pyi +131 -0
- gllm_datastore/encryptor/__init__.pyi +4 -0
- gllm_datastore/encryptor/aes_gcm_encryptor.pyi +45 -0
- gllm_datastore/encryptor/encryptor.pyi +52 -0
- gllm_datastore/encryptor/key_ring/__init__.pyi +3 -0
- gllm_datastore/encryptor/key_ring/in_memory_key_ring.pyi +52 -0
- gllm_datastore/encryptor/key_ring/key_ring.pyi +45 -0
- gllm_datastore/encryptor/key_rotating_encryptor.pyi +60 -0
- gllm_datastore/graph_data_store/__init__.pyi +6 -0
- gllm_datastore/graph_data_store/graph_data_store.pyi +151 -0
- gllm_datastore/graph_data_store/graph_rag_data_store.pyi +29 -0
- gllm_datastore/graph_data_store/light_rag_data_store.pyi +93 -0
- gllm_datastore/graph_data_store/light_rag_postgres_data_store.pyi +96 -0
- gllm_datastore/graph_data_store/llama_index_graph_rag_data_store.pyi +49 -0
- gllm_datastore/graph_data_store/llama_index_neo4j_graph_rag_data_store.pyi +78 -0
- gllm_datastore/graph_data_store/nebula_graph_data_store.pyi +206 -0
- gllm_datastore/graph_data_store/neo4j_graph_data_store.pyi +182 -0
- gllm_datastore/graph_data_store/utils/__init__.pyi +6 -0
- gllm_datastore/graph_data_store/utils/constants.pyi +21 -0
- gllm_datastore/graph_data_store/utils/light_rag_em_invoker_adapter.pyi +56 -0
- gllm_datastore/graph_data_store/utils/light_rag_lm_invoker_adapter.pyi +43 -0
- gllm_datastore/graph_data_store/utils/llama_index_em_invoker_adapter.pyi +45 -0
- gllm_datastore/graph_data_store/utils/llama_index_lm_invoker_adapter.pyi +169 -0
- gllm_datastore/sql_data_store/__init__.pyi +4 -0
- gllm_datastore/sql_data_store/adapter/__init__.pyi +0 -0
- gllm_datastore/sql_data_store/adapter/sqlalchemy_adapter.pyi +38 -0
- gllm_datastore/sql_data_store/constants.pyi +6 -0
- gllm_datastore/sql_data_store/sql_data_store.pyi +86 -0
- gllm_datastore/sql_data_store/sqlalchemy_sql_data_store.pyi +216 -0
- gllm_datastore/sql_data_store/types.pyi +31 -0
- gllm_datastore/utils/__init__.pyi +6 -0
- gllm_datastore/utils/converter.pyi +51 -0
- gllm_datastore/utils/dict.pyi +21 -0
- gllm_datastore/utils/ttl.pyi +25 -0
- gllm_datastore/utils/types.pyi +32 -0
- gllm_datastore/vector_data_store/__init__.pyi +6 -0
- gllm_datastore/vector_data_store/chroma_vector_data_store.pyi +259 -0
- gllm_datastore/vector_data_store/elasticsearch_vector_data_store.pyi +357 -0
- gllm_datastore/vector_data_store/in_memory_vector_data_store.pyi +179 -0
- gllm_datastore/vector_data_store/mixin/__init__.pyi +0 -0
- gllm_datastore/vector_data_store/mixin/cache_compatible_mixin.pyi +145 -0
- gllm_datastore/vector_data_store/redis_vector_data_store.pyi +191 -0
- gllm_datastore/vector_data_store/vector_data_store.pyi +146 -0
- gllm_datastore.build/.gitignore +1 -0
- gllm_datastore.cpython-311-darwin.so +0 -0
- gllm_datastore.pyi +156 -0
- gllm_datastore_binary-0.5.45.dist-info/METADATA +178 -0
- gllm_datastore_binary-0.5.45.dist-info/RECORD +108 -0
- gllm_datastore_binary-0.5.45.dist-info/WHEEL +5 -0
- gllm_datastore_binary-0.5.45.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from elasticsearch import AsyncElasticsearch
|
|
3
|
+
from elasticsearch.dsl import AttrDict as AttrDict
|
|
4
|
+
from enum import StrEnum
|
|
5
|
+
from gllm_core.schema import Chunk
|
|
6
|
+
from gllm_datastore.constants import METADATA_KEYS as METADATA_KEYS
|
|
7
|
+
from gllm_datastore.core.filters.schema import FilterClause as FilterClause, QueryFilter as QueryFilter, QueryOptions as QueryOptions
|
|
8
|
+
from gllm_datastore.data_store.elasticsearch.query import apply_filter_query_to_search as apply_filter_query_to_search, apply_filters_and_options as apply_filters_and_options, create_search_with_filters as create_search_with_filters, delete_by_id as delete_by_id, delete_by_query as delete_by_query, safe_execute as safe_execute, translate_filter as translate_filter, update_by_query as update_by_query, validate_query_length as validate_query_length
|
|
9
|
+
from typing import Any, Literal, overload
|
|
10
|
+
|
|
11
|
+
class SupportedQueryMethods(StrEnum):
|
|
12
|
+
"""Supported query methods for Elasticsearch fulltext capability."""
|
|
13
|
+
AUTOCOMPLETE: str
|
|
14
|
+
AUTOSUGGEST: str
|
|
15
|
+
BM25: str
|
|
16
|
+
BY_FIELD: str
|
|
17
|
+
SHINGLES: str
|
|
18
|
+
|
|
19
|
+
QUERY_REQUIRED_STRATEGIES: Incomplete
|
|
20
|
+
|
|
21
|
+
class ElasticsearchFulltextCapability:
|
|
22
|
+
"""Elasticsearch implementation of FulltextCapability protocol.
|
|
23
|
+
|
|
24
|
+
This class provides document CRUD operations and flexible querying using Elasticsearch.
|
|
25
|
+
|
|
26
|
+
Attributes:
|
|
27
|
+
index_name (str): The name of the Elasticsearch index.
|
|
28
|
+
client (AsyncElasticsearch): AsyncElasticsearch client.
|
|
29
|
+
query_field (str): The field name to use for text content.
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
index_name: Incomplete
|
|
33
|
+
client: Incomplete
|
|
34
|
+
query_field: Incomplete
|
|
35
|
+
def __init__(self, index_name: str, client: AsyncElasticsearch, query_field: str = 'text') -> None:
|
|
36
|
+
'''Initialize the Elasticsearch fulltext capability.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
index_name (str): The name of the Elasticsearch index.
|
|
40
|
+
client (AsyncElasticsearch): The Elasticsearch client.
|
|
41
|
+
query_field (str, optional): The field name to use for text content. Defaults to "text".
|
|
42
|
+
'''
|
|
43
|
+
async def get_size(self) -> int:
|
|
44
|
+
"""Returns the total number of vectors in the index.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
int: The total number of vectors.
|
|
48
|
+
"""
|
|
49
|
+
async def create(self, data: Chunk | list[Chunk], **kwargs: Any) -> None:
|
|
50
|
+
"""Create new records in the datastore.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
data (Chunk | list[Chunk]): Data to create (single item or collection).
|
|
54
|
+
**kwargs: Backend-specific parameters forwarded to Elasticsearch bulk API.
|
|
55
|
+
|
|
56
|
+
Raises:
|
|
57
|
+
ValueError: If data structure is invalid.
|
|
58
|
+
"""
|
|
59
|
+
@overload
|
|
60
|
+
async def retrieve(self, strategy: Literal[SupportedQueryMethods.BY_FIELD] | None = ..., query: str | None = None, filters: FilterClause | QueryFilter | None = None, options: QueryOptions | None = None, **kwargs: Any) -> list[Chunk]: ...
|
|
61
|
+
@overload
|
|
62
|
+
async def retrieve(self, strategy: Literal[SupportedQueryMethods.BM25], query: str, filters: FilterClause | QueryFilter | None = None, options: QueryOptions | None = None, k1: float | None = None, b: float | None = None, **kwargs: Any) -> list[Chunk]: ...
|
|
63
|
+
@overload
|
|
64
|
+
async def retrieve(self, strategy: Literal[SupportedQueryMethods.AUTOCOMPLETE], query: str, field: str, size: int = 20, fuzzy_tolerance: int = 1, min_prefix_length: int = 3, filter_query: dict[str, Any] | None = None, **kwargs: Any) -> list[str]: ...
|
|
65
|
+
@overload
|
|
66
|
+
async def retrieve(self, strategy: Literal[SupportedQueryMethods.AUTOSUGGEST], query: str, search_fields: list[str], autocomplete_field: str, size: int = 20, min_length: int = 3, filter_query: dict[str, Any] | None = None, **kwargs: Any) -> list[str]: ...
|
|
67
|
+
@overload
|
|
68
|
+
async def retrieve(self, strategy: Literal[SupportedQueryMethods.SHINGLES], query: str, field: str, size: int = 20, min_length: int = 3, max_length: int = 30, filter_query: dict[str, Any] | None = None, **kwargs: Any) -> list[str]: ...
|
|
69
|
+
async def retrieve_by_field(self, filters: FilterClause | QueryFilter | None = None, options: QueryOptions | None = None) -> list[Chunk]:
|
|
70
|
+
"""Retrieve records from the datastore based on metadata field filtering.
|
|
71
|
+
|
|
72
|
+
This method filters and returns stored chunks based on metadata values
|
|
73
|
+
rather than text content. It is particularly useful for structured lookups,
|
|
74
|
+
such as retrieving all chunks from a certain source, tagged with a specific label,
|
|
75
|
+
or authored by a particular user.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
filters (FilterClause | QueryFilter | None, optional): Query filters to apply.
|
|
79
|
+
FilterClause objects are automatically converted to QueryFilter internally.
|
|
80
|
+
Defaults to None.
|
|
81
|
+
options (QueryOptions | None, optional): Query options (sorting, pagination, etc.).
|
|
82
|
+
Defaults to None.
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
list[Chunk]: The filtered results as Chunk objects.
|
|
86
|
+
"""
|
|
87
|
+
async def retrieve_bm25(self, query: str, filters: FilterClause | QueryFilter | None = None, options: QueryOptions | None = None, k1: float | None = None, b: float | None = None) -> list[Chunk]:
|
|
88
|
+
'''Queries the Elasticsearch data store using BM25 algorithm for keyword-based search.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
query (str): The query string.
|
|
92
|
+
filters (FilterClause | QueryFilter | None, optional): Optional metadata filter to apply to the search.
|
|
93
|
+
FilterClause objects are automatically converted to QueryFilter internally.
|
|
94
|
+
Use filter builder functions like `F.eq()`, `F.and_()`, etc. Defaults to None.
|
|
95
|
+
options (QueryOptions | None, optional): Query options including fields, limit, order_by, etc.
|
|
96
|
+
For example, `QueryOptions(fields=["title", "content"], limit=10, order_by="score", order_desc=True)`.
|
|
97
|
+
If fields is None, defaults to ["text"]. For multiple fields, uses multi_match query. Defaults to None.
|
|
98
|
+
k1 (float | None, optional): BM25 parameter controlling term frequency saturation.
|
|
99
|
+
Higher values mean term frequency has more impact before diminishing returns.
|
|
100
|
+
Typical values: 1.2-2.0. If None, uses Elasticsearch default (~1.2). Defaults to None.
|
|
101
|
+
b (float | None, optional): BM25 parameter controlling document length normalization.
|
|
102
|
+
0.0 = no length normalization, 1.0 = full normalization.
|
|
103
|
+
Typical values: 0.75. If None, uses Elasticsearch default (~0.75). Defaults to None.
|
|
104
|
+
|
|
105
|
+
Examples:
|
|
106
|
+
```python
|
|
107
|
+
from gllm_datastore.core.filters import filter as F
|
|
108
|
+
|
|
109
|
+
# Basic BM25 query on the \'text\' field
|
|
110
|
+
results = await data_store.query_bm25("machine learning")
|
|
111
|
+
|
|
112
|
+
# BM25 query on specific fields with query options
|
|
113
|
+
results = await data_store.query_bm25(
|
|
114
|
+
"natural language",
|
|
115
|
+
options=QueryOptions(fields=["title", "abstract"], limit=5)
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# BM25 query with direct FilterClause
|
|
119
|
+
results = await data_store.query_bm25(
|
|
120
|
+
"deep learning",
|
|
121
|
+
filters=F.eq("metadata.category", "AI")
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
# BM25 query with multiple filters
|
|
125
|
+
results = await data_store.query_bm25(
|
|
126
|
+
"deep learning",
|
|
127
|
+
filters=F.and_(F.eq("metadata.category", "AI"), F.eq("metadata.status", "published"))
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
# BM25 query with custom BM25 parameters for more aggressive term frequency weighting
|
|
131
|
+
results = await data_store.query_bm25(
|
|
132
|
+
"artificial intelligence",
|
|
133
|
+
k1=2.0,
|
|
134
|
+
b=0.5
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
# BM25 query with fields, filters, and options
|
|
138
|
+
results = await data_store.query_bm25(
|
|
139
|
+
"data science applications",
|
|
140
|
+
filters=F.and_(
|
|
141
|
+
F.eq("metadata.author_id", "user123"),
|
|
142
|
+
F.in_("metadata.publication_year", [2022, 2023])
|
|
143
|
+
),
|
|
144
|
+
options=QueryOptions(fields=["content", "tags"], limit=10, order_by="score", order_desc=True),
|
|
145
|
+
k1=1.5,
|
|
146
|
+
b=0.9
|
|
147
|
+
)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
list[Chunk]: A list of Chunk objects representing the retrieved documents.
|
|
152
|
+
'''
|
|
153
|
+
async def retrieve_autocomplete(self, query: str, field: str, size: int = 20, fuzzy_tolerance: int = 1, min_prefix_length: int = 3, filter_query: dict[str, Any] | None = None) -> list[str]:
|
|
154
|
+
"""Provides suggestions based on a prefix query for a specific field.
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
query (str): The query string.
|
|
158
|
+
field (str): The field name for autocomplete.
|
|
159
|
+
size (int, optional): The number of suggestions to retrieve. Defaults to 20.
|
|
160
|
+
fuzzy_tolerance (int, optional): The level of fuzziness for suggestions. Defaults to 1.
|
|
161
|
+
min_prefix_length (int, optional): The minimum prefix length to trigger fuzzy matching. Defaults to 3.
|
|
162
|
+
filter_query (dict[str, Any] | None, optional): The filter query. Defaults to None.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
list[str]: A list of suggestions.
|
|
166
|
+
"""
|
|
167
|
+
async def retrieve_autosuggest(self, query: str, search_fields: list[str], autocomplete_field: str, size: int = 20, min_length: int = 3, filters: QueryFilter | None = None) -> list[str]:
|
|
168
|
+
"""Generates suggestions across multiple fields using a multi_match query to broaden the search criteria.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
query (str): The query string.
|
|
172
|
+
search_fields (list[str]): The fields to search for.
|
|
173
|
+
autocomplete_field (str): The field name for autocomplete.
|
|
174
|
+
size (int, optional): The number of suggestions to retrieve. Defaults to 20.
|
|
175
|
+
min_length (int, optional): The minimum length of the query. Defaults to 3.
|
|
176
|
+
filters (QueryFilter | None, optional): The filter query. Defaults to None.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
list[str]: A list of suggestions.
|
|
180
|
+
"""
|
|
181
|
+
async def retrieve_shingles(self, query: str, field: str, size: int = 20, min_length: int = 3, max_length: int = 30, filters: QueryFilter | None = None) -> list[str]:
|
|
182
|
+
"""Searches using shingles for prefix and fuzzy matching.
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
query (str): The query string.
|
|
186
|
+
field (str): The field name for autocomplete.
|
|
187
|
+
size (int, optional): The number of suggestions to retrieve. Defaults to 20.
|
|
188
|
+
min_length (int, optional): The minimum length of the query.
|
|
189
|
+
Queries shorter than this limit will return an empty list. Defaults to 3.
|
|
190
|
+
max_length (int, optional): The maximum length of the query.
|
|
191
|
+
Queries exceeding this limit will return an empty list. Defaults to 30.
|
|
192
|
+
filters (QueryFilter | None, optional): The filter query. Defaults to None.
|
|
193
|
+
|
|
194
|
+
Returns:
|
|
195
|
+
list[str]: A list of suggestions.
|
|
196
|
+
"""
|
|
197
|
+
async def retrieve_fuzzy(self, query: str, max_distance: int = 2, filters: FilterClause | QueryFilter | None = None, options: QueryOptions | None = None) -> list[Chunk]:
|
|
198
|
+
"""Find records that fuzzy match the query within distance threshold.
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
query (str): Text to fuzzy match against.
|
|
202
|
+
max_distance (int): Maximum edit distance for matches. Defaults to 2.
|
|
203
|
+
filters (FilterClause | QueryFilter | None, optional): Optional metadata filters to apply.
|
|
204
|
+
FilterClause objects are automatically converted to QueryFilter internally.
|
|
205
|
+
Defaults to None.
|
|
206
|
+
options (QueryOptions | None, optional): Query options (limit, sorting, etc.). Defaults to None.
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
list[Chunk]: Matched chunks.
|
|
210
|
+
"""
|
|
211
|
+
async def update(self, update_values: dict[str, Any], filters: FilterClause | QueryFilter | None = None) -> None:
|
|
212
|
+
"""Update existing records in the datastore.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
update_values (dict[str, Any]): Values to update.
|
|
216
|
+
filters (FilterClause | QueryFilter | None, optional): Filters to select records to update.
|
|
217
|
+
FilterClause objects are automatically converted to QueryFilter internally.
|
|
218
|
+
Defaults to None.
|
|
219
|
+
"""
|
|
220
|
+
async def delete(self, filters: FilterClause | QueryFilter | None = None, options: QueryOptions | None = None) -> None:
|
|
221
|
+
"""Delete records from the data store using filters and optional options.
|
|
222
|
+
|
|
223
|
+
Args:
|
|
224
|
+
filters (FilterClause | QueryFilter | None, optional): Filters to select records for deletion.
|
|
225
|
+
FilterClause objects are automatically converted to QueryFilter internally.
|
|
226
|
+
Defaults to None.
|
|
227
|
+
options (QueryOptions | None, optional): Query options supporting limit and sorting
|
|
228
|
+
for eviction-like operations. Defaults to None.
|
|
229
|
+
"""
|
|
230
|
+
async def delete_by_id(self, id_: str | list[str]) -> None:
|
|
231
|
+
"""Deletes records from the data store based on IDs.
|
|
232
|
+
|
|
233
|
+
Args:
|
|
234
|
+
id_ (str | list[str]): ID or list of IDs to delete.
|
|
235
|
+
"""
|
|
236
|
+
async def clear(self) -> None:
|
|
237
|
+
"""Clear all records from the datastore."""
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from elasticsearch import AsyncElasticsearch
|
|
3
|
+
from elasticsearch.dsl import AsyncSearch
|
|
4
|
+
from elasticsearch.dsl.query import Query
|
|
5
|
+
from elasticsearch.dsl.response import Response
|
|
6
|
+
from gllm_datastore.core.filters.schema import FilterClause as FilterClause, FilterCondition as FilterCondition, FilterOperator as FilterOperator, QueryFilter as QueryFilter, QueryOptions as QueryOptions
|
|
7
|
+
from gllm_datastore.utils import flatten_dict as flatten_dict
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
def apply_filters_and_options(search: AsyncSearch, filters: QueryFilter | None = None, options: QueryOptions | None = None) -> AsyncSearch:
|
|
11
|
+
"""Apply filters and options to an Elasticsearch search object.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
search (AsyncSearch): Elasticsearch search object.
|
|
15
|
+
filters (QueryFilter | None, optional): New QueryFilter with filters and condition.
|
|
16
|
+
options (QueryOptions | None, optional): Query options (limit, sort, fields).
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
AsyncSearch: Elasticsearch search object.
|
|
20
|
+
"""
|
|
21
|
+
def translate_filter(filters: QueryFilter | None) -> Query | None:
|
|
22
|
+
"""Translate a structured QueryFilter into an Elasticsearch DSL Query.
|
|
23
|
+
|
|
24
|
+
The translation supports comparison operators (EQ, NE, GT, LT, GTE, LTE),
|
|
25
|
+
array operators (IN, NIN, ARRAY_CONTAINS, ANY, ALL), text operators (TEXT_CONTAINS),
|
|
26
|
+
and logical conditions (AND, OR, NOT), including nested filters.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
filters (QueryFilter | None): Structured QueryFilter. If None, returns None.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
Query | None: An Elasticsearch Query object or None if no filters are provided.
|
|
33
|
+
|
|
34
|
+
Raises:
|
|
35
|
+
ValueError: When the filter structure is invalid.
|
|
36
|
+
TypeError: When an operator-value type combination is invalid.
|
|
37
|
+
"""
|
|
38
|
+
async def update_by_query(client: AsyncElasticsearch, index_name: str, update_values: dict[str, Any], filters: QueryFilter | None = None, logger: logging.Logger | None = None) -> None:
|
|
39
|
+
'''Update records in Elasticsearch using UpdateByQuery with retry logic for version conflicts.
|
|
40
|
+
|
|
41
|
+
This function builds a painless script that safely assigns each updated field.
|
|
42
|
+
When a field path contains dots (e.g. "metadata.cache_value"), we must
|
|
43
|
+
access the corresponding param using bracket syntax: params[\'metadata.cache_value\']
|
|
44
|
+
to avoid Painless treating it as nested object access (which would be None).
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
client (AsyncElasticsearch): Elasticsearch client instance.
|
|
48
|
+
index_name (str): The name of the Elasticsearch index.
|
|
49
|
+
update_values (dict[str, Any]): Values to update.
|
|
50
|
+
filters (QueryFilter | None, optional): New QueryFilter to select records to update.
|
|
51
|
+
Defaults to None.
|
|
52
|
+
logger (Any | None, optional): Logger instance. Defaults to None.
|
|
53
|
+
'''
|
|
54
|
+
async def delete_by_query(client: AsyncElasticsearch, index_name: str, filters: QueryFilter | None = None) -> None:
|
|
55
|
+
"""Delete records from Elasticsearch using delete_by_query.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
client (AsyncElasticsearch): Elasticsearch client instance.
|
|
59
|
+
index_name (str): The name of the Elasticsearch index.
|
|
60
|
+
filters (QueryFilter | None, optional): New QueryFilter to select records for deletion.
|
|
61
|
+
Defaults to None, in which case no operation will be performed.
|
|
62
|
+
"""
|
|
63
|
+
async def delete_by_id(client: AsyncElasticsearch, index_name: str, ids: str | list[str]) -> None:
|
|
64
|
+
"""Delete records from Elasticsearch by IDs using Search.delete().
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
client (AsyncElasticsearch): Elasticsearch client instance.
|
|
68
|
+
index_name (str): The name of the Elasticsearch index.
|
|
69
|
+
ids (str | list[str]): ID or list of IDs to delete.
|
|
70
|
+
"""
|
|
71
|
+
def validate_query_length(query: str, min_length: int = 0, max_length: int | None = None) -> bool:
|
|
72
|
+
"""Validate query length against minimum and maximum constraints.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
query (str): The query string to validate.
|
|
76
|
+
min_length (int, optional): Minimum required length. Defaults to 0.
|
|
77
|
+
max_length (int | None, optional): Maximum allowed length. Defaults to None.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
bool: True if query is valid, False otherwise.
|
|
81
|
+
"""
|
|
82
|
+
def create_search_with_filters(client: AsyncElasticsearch, index_name: str, filters: QueryFilter | None = None, exclude_fields: list[str] | None = None) -> AsyncSearch:
|
|
83
|
+
"""Create an AsyncSearch object with optional filters and field exclusions.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
client (AsyncElasticsearch): Elasticsearch client instance.
|
|
87
|
+
index_name (str): The name of the Elasticsearch index.
|
|
88
|
+
filters (QueryFilter | None, optional): New QueryFilter to apply. Defaults to None.
|
|
89
|
+
exclude_fields (list[str] | None, optional): Fields to exclude from source. Defaults to None.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
AsyncSearch: Configured AsyncSearch object.
|
|
93
|
+
"""
|
|
94
|
+
def apply_filter_query_to_search(search: AsyncSearch, main_query: Query, filters: QueryFilter | None = None) -> AsyncSearch:
|
|
95
|
+
"""Apply filter query to a search with a main query.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
search (AsyncSearch): Elasticsearch search object.
|
|
99
|
+
main_query (Query): The main query to apply.
|
|
100
|
+
filters (QueryFilter | None, optional): Query filters to apply. Defaults to None.
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
AsyncSearch: Search object with applied queries.
|
|
104
|
+
"""
|
|
105
|
+
async def safe_execute(search: AsyncSearch, logger: logging.Logger | None = None) -> Response | None:
|
|
106
|
+
"""Execute an Elasticsearch DSL search with unified error handling.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
search (AsyncSearch): Elasticsearch DSL AsyncSearch object.
|
|
110
|
+
logger (logging.Logger | None, optional): Logger instance for error messages. Defaults to None.
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
Response | None: The Elasticsearch response on success, otherwise None.
|
|
114
|
+
"""
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from elasticsearch import AsyncElasticsearch
|
|
3
|
+
from gllm_core.schema import Chunk
|
|
4
|
+
from gllm_datastore.constants import DEFAULT_FETCH_K as DEFAULT_FETCH_K, DEFAULT_TOP_K as DEFAULT_TOP_K
|
|
5
|
+
from gllm_datastore.core.filters.schema import FilterClause as FilterClause, QueryFilter as QueryFilter, QueryOptions as QueryOptions
|
|
6
|
+
from gllm_datastore.data_store.elasticsearch.query import delete_by_id as delete_by_id, delete_by_query as delete_by_query, translate_filter as translate_filter, update_by_query as update_by_query
|
|
7
|
+
from gllm_datastore.utils.converter import from_langchain as from_langchain, to_langchain as to_langchain
|
|
8
|
+
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker
|
|
9
|
+
from gllm_inference.schema import Vector
|
|
10
|
+
from langchain_elasticsearch.vectorstores import AsyncRetrievalStrategy
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
class ElasticsearchVectorCapability:
|
|
14
|
+
"""Elasticsearch implementation of VectorCapability protocol.
|
|
15
|
+
|
|
16
|
+
This class provides document CRUD operations and vector search using Elasticsearch.
|
|
17
|
+
|
|
18
|
+
Attributes:
|
|
19
|
+
index_name (str): The name of the Elasticsearch index.
|
|
20
|
+
vector_store (AsyncElasticsearchStore): The vector store instance.
|
|
21
|
+
em_invoker (BaseEMInvoker): The embedding model to perform vectorization.
|
|
22
|
+
"""
|
|
23
|
+
index_name: Incomplete
|
|
24
|
+
vector_store: Incomplete
|
|
25
|
+
def __init__(self, index_name: str, client: AsyncElasticsearch, em_invoker: BaseEMInvoker, query_field: str = 'text', vector_query_field: str = 'vector', retrieval_strategy: AsyncRetrievalStrategy | None = None, distance_strategy: str | None = None) -> None:
|
|
26
|
+
'''Initialize the Elasticsearch vector capability.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
index_name (str): The name of the Elasticsearch index.
|
|
30
|
+
client (AsyncElasticsearch): The Elasticsearch client.
|
|
31
|
+
em_invoker (BaseEMInvoker): The embedding model to perform vectorization.
|
|
32
|
+
query_field (str, optional): The field name for text queries. Defaults to "text".
|
|
33
|
+
vector_query_field (str, optional): The field name for vector queries. Defaults to "vector".
|
|
34
|
+
retrieval_strategy (AsyncRetrievalStrategy | None, optional): The retrieval strategy for retrieval.
|
|
35
|
+
Defaults to None, in which case DenseVectorStrategy() is used.
|
|
36
|
+
distance_strategy (str | None, optional): The distance strategy for retrieval. Defaults to None.
|
|
37
|
+
'''
|
|
38
|
+
@property
|
|
39
|
+
def em_invoker(self) -> BaseEMInvoker:
|
|
40
|
+
"""Returns the EM Invoker instance.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
BaseEMInvoker: The EM Invoker instance.
|
|
44
|
+
"""
|
|
45
|
+
async def ensure_index(self, mapping: dict[str, Any] | None = None, index_settings: dict[str, Any] | None = None, dimension: int | None = None, distance_strategy: str | None = None) -> None:
|
|
46
|
+
'''Ensure Elasticsearch index exists, creating it if necessary.
|
|
47
|
+
|
|
48
|
+
This method is idempotent - if the index already exists, it will skip creation
|
|
49
|
+
and return early.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
mapping (dict[str, Any] | None, optional): Custom mapping dictionary to use
|
|
53
|
+
for index creation. If provided, this mapping will be used directly.
|
|
54
|
+
The mapping should follow Elasticsearch mapping format. Defaults to None,
|
|
55
|
+
in which default mapping will be used.
|
|
56
|
+
index_settings (dict[str, Any] | None, optional): Custom index settings.
|
|
57
|
+
These settings will be merged with any default settings. Defaults to None.
|
|
58
|
+
dimension (int | None, optional): Vector dimension. If not provided and mapping
|
|
59
|
+
is not provided, will be inferred from em_invoker by generating a test embedding.
|
|
60
|
+
distance_strategy (str | None, optional): Distance strategy for vector similarity.
|
|
61
|
+
Supported values: "cosine", "l2_norm", "dot_product", etc.
|
|
62
|
+
Only used when building default mapping. Defaults to "cosine" if not specified.
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
ValueError: If mapping is invalid or required parameters are missing.
|
|
66
|
+
RuntimeError: If index creation fails.
|
|
67
|
+
'''
|
|
68
|
+
async def create(self, data: Chunk | list[Chunk], **kwargs: Any) -> None:
|
|
69
|
+
"""Create new records in the datastore.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
data (Chunk | list[Chunk]): Data to create (single item or collection).
|
|
73
|
+
**kwargs: Datastore-specific parameters.
|
|
74
|
+
|
|
75
|
+
Raises:
|
|
76
|
+
ValueError: If data structure is invalid.
|
|
77
|
+
"""
|
|
78
|
+
async def create_from_vector(self, chunk_vectors: list[tuple[Chunk, Vector]], **kwargs) -> list[str]:
|
|
79
|
+
"""Add pre-computed embeddings directly.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
chunk_vectors (list[tuple[Chunk, Vector]]): List of tuples containing chunks and their
|
|
83
|
+
corresponding vectors.
|
|
84
|
+
**kwargs: Datastore-specific parameters.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
list[str]: List of IDs assigned to added embeddings.
|
|
88
|
+
"""
|
|
89
|
+
async def retrieve(self, query: str, filters: FilterClause | QueryFilter | None = None, options: QueryOptions | None = None, **kwargs: Any) -> list[Chunk]:
|
|
90
|
+
'''Semantic search using text query converted to vector.
|
|
91
|
+
|
|
92
|
+
Usage Example:
|
|
93
|
+
```python
|
|
94
|
+
from gllm_datastore.core.filters import filter as F
|
|
95
|
+
|
|
96
|
+
# Direct FilterClause usage
|
|
97
|
+
await vector_capability.retrieve(
|
|
98
|
+
query="What is the capital of France?",
|
|
99
|
+
filters=F.eq("metadata.category", "tech"),
|
|
100
|
+
options=QueryOptions(limit=10),
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# Multiple filters
|
|
104
|
+
filters = F.and_(F.eq("metadata.source", "wikipedia"), F.eq("metadata.category", "tech"))
|
|
105
|
+
await vector_capability.retrieve(query="What is the capital of France?", filters=filters)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
query (str): Text query to embed and search for.
|
|
110
|
+
filters (FilterClause | QueryFilter | None, optional): Filters to apply to the search.
|
|
111
|
+
FilterClause objects are automatically converted to QueryFilter internally.
|
|
112
|
+
Defaults to None.
|
|
113
|
+
options (QueryOptions | None, optional): Options to apply to the search. Defaults to None.
|
|
114
|
+
**kwargs: Datastore-specific parameters.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
list[Chunk]: List of chunks ordered by relevance score.
|
|
118
|
+
'''
|
|
119
|
+
async def retrieve_by_vector(self, vector: Vector, filters: FilterClause | QueryFilter | None = None, options: QueryOptions | None = None) -> list[Chunk]:
|
|
120
|
+
'''Direct vector similarity search.
|
|
121
|
+
|
|
122
|
+
Usage Example:
|
|
123
|
+
```python
|
|
124
|
+
from gllm_datastore.core.filters import filter as F
|
|
125
|
+
|
|
126
|
+
# Direct FilterClause usage
|
|
127
|
+
await vector_capability.retrieve_by_vector(
|
|
128
|
+
vector=[0.1, 0.2, 0.3],
|
|
129
|
+
filters=F.eq("metadata.category", "tech"),
|
|
130
|
+
options=QueryOptions(limit=10),
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# Multiple filters
|
|
134
|
+
filters = F.and_(F.eq("metadata.source", "wikipedia"), F.eq("metadata.category", "tech"))
|
|
135
|
+
await vector_capability.retrieve_by_vector(vector=[0.1, 0.2, 0.3], filters=filters)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
vector (Vector): Query embedding vector.
|
|
140
|
+
filters (FilterClause | QueryFilter | None, optional): Filters to apply to the search.
|
|
141
|
+
FilterClause objects are automatically converted to QueryFilter internally.
|
|
142
|
+
Defaults to None.
|
|
143
|
+
options (QueryOptions | None, optional): Options to apply to the search. Defaults to None.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
list[Chunk]: List of chunks ordered by similarity score.
|
|
147
|
+
'''
|
|
148
|
+
async def update(self, update_values: dict, filters: FilterClause | QueryFilter | None = None, **kwargs: Any) -> None:
|
|
149
|
+
"""Update existing records in the datastore.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
update_values (dict): Values to update.
|
|
153
|
+
filters (FilterClause | QueryFilter | None, optional): Filters to select records to update.
|
|
154
|
+
FilterClause objects are automatically converted to QueryFilter internally.
|
|
155
|
+
Defaults to None.
|
|
156
|
+
**kwargs: Datastore-specific parameters.
|
|
157
|
+
"""
|
|
158
|
+
async def delete(self, filters: FilterClause | QueryFilter | None = None, **kwargs: Any) -> None:
|
|
159
|
+
"""Delete records from the data store based on filters.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
filters (FilterClause | QueryFilter | None, optional): Filters to select records for deletion.
|
|
163
|
+
FilterClause objects are automatically converted to QueryFilter internally.
|
|
164
|
+
Defaults to None.
|
|
165
|
+
**kwargs: Datastore-specific parameters.
|
|
166
|
+
"""
|
|
167
|
+
async def delete_by_id(self, id: str | list[str], **kwargs: Any) -> None:
|
|
168
|
+
"""Delete records from the data store based on IDs.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
id (str | list[str]): ID or list of IDs to delete.
|
|
172
|
+
**kwargs: Datastore-specific parameters.
|
|
173
|
+
"""
|
|
174
|
+
async def clear(self, **kwargs: Any) -> None:
|
|
175
|
+
"""Clear all records from the datastore.
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
**kwargs: Datastore-specific parameters.
|
|
179
|
+
"""
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
|
|
3
|
+
class NotSupportedException(Exception):
|
|
4
|
+
"""Raised when attempting to access an unsupported capability.
|
|
5
|
+
|
|
6
|
+
This exception is raised when code attempts to access a capability
|
|
7
|
+
that isn't configured for a datastore.
|
|
8
|
+
"""
|
|
9
|
+
capability: Incomplete
|
|
10
|
+
class_name: Incomplete
|
|
11
|
+
class_obj: Incomplete
|
|
12
|
+
def __init__(self, capability: str, class_obj: type) -> None:
|
|
13
|
+
"""Initialize the exception.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
capability (str): The name of the unsupported capability.
|
|
17
|
+
class_obj (Type): The class object for context.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
class NotRegisteredException(Exception):
|
|
21
|
+
"""Raised when attempting to access a capability that is not registered.
|
|
22
|
+
|
|
23
|
+
This exception is raised when code attempts to access a capability
|
|
24
|
+
that is not registered for a datastore but is supported by the datastore.
|
|
25
|
+
"""
|
|
26
|
+
capability: Incomplete
|
|
27
|
+
class_name: Incomplete
|
|
28
|
+
class_obj: Incomplete
|
|
29
|
+
def __init__(self, capability: str, class_obj: type) -> None:
|
|
30
|
+
"""Initialize the exception.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
capability (str): The name of the unregistered capability.
|
|
34
|
+
class_obj (Type): The class object for context.
|
|
35
|
+
"""
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
from gllm_datastore.data_store.in_memory.data_store import InMemoryDataStore as InMemoryDataStore
|
|
2
|
+
from gllm_datastore.data_store.in_memory.fulltext import InMemoryFulltextCapability as InMemoryFulltextCapability
|
|
3
|
+
from gllm_datastore.data_store.in_memory.vector import InMemoryVectorCapability as InMemoryVectorCapability
|
|
4
|
+
|
|
5
|
+
__all__ = ['InMemoryDataStore', 'InMemoryFulltextCapability', 'InMemoryVectorCapability']
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from gllm_core.schema import Chunk as Chunk
|
|
2
|
+
from gllm_datastore.core.filters.schema import FilterClause as FilterClause, QueryFilter as QueryFilter
|
|
3
|
+
from gllm_datastore.data_store.base import BaseDataStore as BaseDataStore, CapabilityType as CapabilityType
|
|
4
|
+
from gllm_datastore.data_store.in_memory.fulltext import InMemoryFulltextCapability as InMemoryFulltextCapability
|
|
5
|
+
from gllm_datastore.data_store.in_memory.vector import InMemoryVectorCapability as InMemoryVectorCapability
|
|
6
|
+
|
|
7
|
+
class InMemoryDataStore(BaseDataStore):
|
|
8
|
+
"""In-memory data store with multiple capability support.
|
|
9
|
+
|
|
10
|
+
This class provides a unified interface for accessing vector, fulltext,
|
|
11
|
+
and cache capabilities using in-memory storage optimized for development
|
|
12
|
+
and testing scenarios.
|
|
13
|
+
|
|
14
|
+
Attributes:
|
|
15
|
+
store (dict[str, Chunk]): Dictionary storing data with their IDs as keys.
|
|
16
|
+
"""
|
|
17
|
+
store: dict[str, Chunk]
|
|
18
|
+
def __init__(self) -> None:
|
|
19
|
+
"""Initialize the in-memory data store."""
|
|
20
|
+
@property
|
|
21
|
+
def supported_capabilities(self) -> list[CapabilityType]:
|
|
22
|
+
"""Return list of currently supported capabilities.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
list[str]: List of capability names that are supported.
|
|
26
|
+
"""
|
|
27
|
+
@property
|
|
28
|
+
def fulltext(self) -> InMemoryFulltextCapability:
|
|
29
|
+
"""Access fulltext capability if registered.
|
|
30
|
+
|
|
31
|
+
This method solely uses the logic of its parent class to return the fulltext capability handler.
|
|
32
|
+
This method overrides the parent class to return the InMemoryFulltextCapability handler for better
|
|
33
|
+
type hinting.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
InMemoryFulltextCapability: Fulltext capability handler.
|
|
37
|
+
|
|
38
|
+
Raises:
|
|
39
|
+
NotRegisteredException: If fulltext capability is not registered.
|
|
40
|
+
"""
|
|
41
|
+
@property
|
|
42
|
+
def vector(self) -> InMemoryVectorCapability:
|
|
43
|
+
"""Access vector capability if registered.
|
|
44
|
+
|
|
45
|
+
This method solely uses the logic of its parent class to return the vector capability handler.
|
|
46
|
+
This method overrides the parent class to return the InMemoryVectorCapability handler for better
|
|
47
|
+
type hinting.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
InMemoryVectorCapability: Vector capability handler.
|
|
51
|
+
|
|
52
|
+
Raises:
|
|
53
|
+
NotRegisteredException: If vector capability is not registered.
|
|
54
|
+
"""
|
|
55
|
+
@classmethod
|
|
56
|
+
def translate_query_filter(cls, query_filter: FilterClause | QueryFilter | None) -> FilterClause | QueryFilter | None:
|
|
57
|
+
"""Translate QueryFilter or FilterClause to in-memory datastore filter syntax.
|
|
58
|
+
|
|
59
|
+
For the in-memory datastore, this method acts as an identity function since
|
|
60
|
+
the datastore works directly with the QueryFilter DSL without requiring
|
|
61
|
+
translation to a native format.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
query_filter (FilterClause | QueryFilter | None): The filter to translate.
|
|
65
|
+
Can be a single FilterClause, a QueryFilter with multiple clauses,
|
|
66
|
+
or None for empty filters.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
FilterClause | QueryFilter | None: The same filter object that was passed in.
|
|
70
|
+
Returns None for empty filters.
|
|
71
|
+
"""
|