ahnlich-client-py 0.0.0__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.
- VERSION +2 -0
- ahnlich_client_py/__init__.py +5 -0
- ahnlich_client_py/builders/__init__.py +10 -0
- ahnlich_client_py/builders/ai.py +174 -0
- ahnlich_client_py/builders/db.py +163 -0
- ahnlich_client_py/builders/non_blocking/__init__.py +2 -0
- ahnlich_client_py/builders/non_blocking/ai.py +16 -0
- ahnlich_client_py/builders/non_blocking/db.py +16 -0
- ahnlich_client_py/clients/__init__.py +2 -0
- ahnlich_client_py/clients/ai.py +224 -0
- ahnlich_client_py/clients/db.py +224 -0
- ahnlich_client_py/clients/non_blocking/__init__.py +2 -0
- ahnlich_client_py/clients/non_blocking/ai.py +226 -0
- ahnlich_client_py/clients/non_blocking/db.py +225 -0
- ahnlich_client_py/config.py +18 -0
- ahnlich_client_py/exceptions.py +10 -0
- ahnlich_client_py/internals/__init__.py +0 -0
- ahnlich_client_py/internals/ai_query.py +532 -0
- ahnlich_client_py/internals/ai_response.py +461 -0
- ahnlich_client_py/internals/async_base_client.py +90 -0
- ahnlich_client_py/internals/base_client.py +84 -0
- ahnlich_client_py/internals/bincode/__init__.py +77 -0
- ahnlich_client_py/internals/db_query.py +381 -0
- ahnlich_client_py/internals/db_response.py +340 -0
- ahnlich_client_py/internals/pool_wrapper.py +46 -0
- ahnlich_client_py/internals/protocol.py +143 -0
- ahnlich_client_py/internals/serde_binary/__init__.py +418 -0
- ahnlich_client_py/internals/serde_types/__init__.py +75 -0
- ahnlich_client_py/libs.py +23 -0
- ahnlich_client_py-0.0.0.dist-info/METADATA +708 -0
- ahnlich_client_py-0.0.0.dist-info/RECORD +33 -0
- ahnlich_client_py-0.0.0.dist-info/WHEEL +4 -0
- ahnlich_client_py-0.0.0.dist-info/entry_points.txt +4 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
from ahnlich_client_py import builders, libs
|
|
2
|
+
from ahnlich_client_py.clients import AhnlichAIClient, AhnlichDBClient
|
|
3
|
+
from ahnlich_client_py.clients import non_blocking as non_blocking_client
|
|
4
|
+
from ahnlich_client_py.config import AhnlichPoolSettings
|
|
5
|
+
from ahnlich_client_py.internals import ai_query, ai_response, db_query, db_response
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from .ai import AhnlichAIRequestBuilder
|
|
2
|
+
from .db import AhnlichDBRequestBuilder
|
|
3
|
+
from .non_blocking import AsyncAhnlichAIRequestBuilder, AsyncAhnlichDBRequestBuilder
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"AhnlichDBRequestBuilder",
|
|
7
|
+
"AhnlichAIRequestBuilder",
|
|
8
|
+
"AsyncAhnlichDBRequestBuilder",
|
|
9
|
+
"AsyncAhnlichAIRequestBuilder",
|
|
10
|
+
]
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from ahnlich_client_py import exceptions as ah_exceptions
|
|
4
|
+
from ahnlich_client_py.internals import ai_query, ai_response
|
|
5
|
+
from ahnlich_client_py.internals import serde_types as st
|
|
6
|
+
from ahnlich_client_py.internals.base_client import BaseClient
|
|
7
|
+
from ahnlich_client_py.libs import NonZeroSizeInteger
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AhnlichAIRequestBuilder:
|
|
11
|
+
def __init__(self, tracing_id: str = None, client: BaseClient = None) -> None:
|
|
12
|
+
self.queries: typing.List[ai_query.AIQuery] = []
|
|
13
|
+
self.tracing_id = tracing_id
|
|
14
|
+
self.client: BaseClient = client
|
|
15
|
+
|
|
16
|
+
def create_store(
|
|
17
|
+
self,
|
|
18
|
+
store_name: str,
|
|
19
|
+
query_model: ai_query.AIModel = ai_query.AIModel__AllMiniLML6V2,
|
|
20
|
+
index_model: ai_query.AIModel = ai_query.AIModel__AllMiniLML6V2,
|
|
21
|
+
predicates: typing.Sequence[str] = None,
|
|
22
|
+
non_linear_indices: typing.Sequence[ai_query.NonLinearAlgorithm] = None,
|
|
23
|
+
error_if_exists: bool = True,
|
|
24
|
+
store_original: bool = True,
|
|
25
|
+
):
|
|
26
|
+
if not non_linear_indices:
|
|
27
|
+
non_linear_indices = []
|
|
28
|
+
if not predicates:
|
|
29
|
+
predicates = []
|
|
30
|
+
|
|
31
|
+
self.queries.append(
|
|
32
|
+
ai_query.AIQuery__CreateStore(
|
|
33
|
+
store=store_name,
|
|
34
|
+
query_model=query_model,
|
|
35
|
+
index_model=index_model,
|
|
36
|
+
predicates=predicates,
|
|
37
|
+
non_linear_indices=non_linear_indices,
|
|
38
|
+
error_if_exists=error_if_exists,
|
|
39
|
+
store_original=store_original,
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def get_pred(self, store_name: str, condition: ai_query.PredicateCondition):
|
|
44
|
+
self.queries.append(
|
|
45
|
+
ai_query.AIQuery__GetPred(store=store_name, condition=condition)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def get_sim_n(
|
|
49
|
+
self,
|
|
50
|
+
store_name: str,
|
|
51
|
+
search_input: ai_query.StoreInput,
|
|
52
|
+
closest_n: st.uint64 = 1,
|
|
53
|
+
algorithm: ai_query.Algorithm = ai_query.Algorithm__CosineSimilarity,
|
|
54
|
+
condition: typing.Optional[ai_query.PredicateCondition] = None,
|
|
55
|
+
preprocess_action: ai_query.PreprocessAction = ai_query.PreprocessAction__ModelPreprocessing,
|
|
56
|
+
):
|
|
57
|
+
nonzero_n = NonZeroSizeInteger(closest_n)
|
|
58
|
+
self.queries.append(
|
|
59
|
+
ai_query.AIQuery__GetSimN(
|
|
60
|
+
store=store_name,
|
|
61
|
+
search_input=search_input,
|
|
62
|
+
closest_n=nonzero_n.value,
|
|
63
|
+
algorithm=algorithm,
|
|
64
|
+
condition=condition,
|
|
65
|
+
preprocess_action=preprocess_action,
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def create_pred_index(self, store_name: str, predicates: typing.Sequence[str]):
|
|
70
|
+
self.queries.append(
|
|
71
|
+
ai_query.AIQuery__CreatePredIndex(store=store_name, predicates=predicates)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def create_non_linear_algorithm_index(
|
|
75
|
+
self,
|
|
76
|
+
store_name: str,
|
|
77
|
+
non_linear_indices: typing.Sequence["NonLinearAlgorithm"],
|
|
78
|
+
):
|
|
79
|
+
self.queries.append(
|
|
80
|
+
ai_query.AIQuery__CreateNonLinearAlgorithmIndex(
|
|
81
|
+
store=store_name, non_linear_indices=non_linear_indices
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
def drop_pred_index(
|
|
86
|
+
self,
|
|
87
|
+
store_name: str,
|
|
88
|
+
predicates: typing.Sequence[str],
|
|
89
|
+
error_if_not_exists: bool = True,
|
|
90
|
+
):
|
|
91
|
+
self.queries.append(
|
|
92
|
+
ai_query.AIQuery__DropPredIndex(
|
|
93
|
+
store=store_name,
|
|
94
|
+
predicates=predicates,
|
|
95
|
+
error_if_not_exists=error_if_not_exists,
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
def drop_non_linear_algorithm_index(
|
|
100
|
+
self,
|
|
101
|
+
store_name: str,
|
|
102
|
+
non_linear_indices: typing.Sequence["NonLinearAlgorithm"],
|
|
103
|
+
error_if_not_exists: bool = True,
|
|
104
|
+
):
|
|
105
|
+
self.queries.append(
|
|
106
|
+
ai_query.AIQuery__DropNonLinearAlgorithmIndex(
|
|
107
|
+
store=store_name,
|
|
108
|
+
non_linear_indices=non_linear_indices,
|
|
109
|
+
error_if_not_exists=error_if_not_exists,
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def set(
|
|
114
|
+
self,
|
|
115
|
+
store_name: str,
|
|
116
|
+
inputs: typing.Sequence[
|
|
117
|
+
typing.Tuple[ai_query.StoreInput, typing.Dict[str, ai_query.MetadataValue]]
|
|
118
|
+
],
|
|
119
|
+
preprocess_action: ai_query.PreprocessAction = ai_query.PreprocessAction__NoPreprocessing,
|
|
120
|
+
):
|
|
121
|
+
self.queries.append(
|
|
122
|
+
ai_query.AIQuery__Set(
|
|
123
|
+
store=store_name,
|
|
124
|
+
inputs=inputs,
|
|
125
|
+
preprocess_action=preprocess_action,
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
def del_key(self, store_name: str, key: ai_query.StoreInput):
|
|
130
|
+
self.queries.append(ai_query.AIQuery__DelKey(store=store_name, key=key))
|
|
131
|
+
|
|
132
|
+
def get_key(self, store_name: str, keys: typing.Sequence[ai_query.StoreInput]):
|
|
133
|
+
self.queries.append(ai_query.AIQuery__GetKey(store=store_name, keys=keys))
|
|
134
|
+
|
|
135
|
+
def drop_store(self, store_name: str, error_if_not_exists: bool = True):
|
|
136
|
+
self.queries.append(
|
|
137
|
+
ai_query.AIQuery__DropStore(
|
|
138
|
+
store=store_name, error_if_not_exists=error_if_not_exists
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def purge_stores(self):
|
|
143
|
+
self.queries.append(ai_query.AIQuery__PurgeStores())
|
|
144
|
+
|
|
145
|
+
def info_server(self):
|
|
146
|
+
self.queries.append(ai_query.AIQuery__InfoServer())
|
|
147
|
+
|
|
148
|
+
def list_stores(self):
|
|
149
|
+
self.queries.append(ai_query.AIQuery__ListStores())
|
|
150
|
+
|
|
151
|
+
def list_clients(self):
|
|
152
|
+
self.queries.append(ai_query.AIQuery__ListClients())
|
|
153
|
+
|
|
154
|
+
def ping(self):
|
|
155
|
+
self.queries.append(ai_query.AIQuery__Ping())
|
|
156
|
+
|
|
157
|
+
def drop(self):
|
|
158
|
+
self.queries.clear()
|
|
159
|
+
|
|
160
|
+
def to_server_query(self) -> ai_query.AIServerQuery:
|
|
161
|
+
if not self.queries:
|
|
162
|
+
raise ah_exceptions.AhnlichClientException(
|
|
163
|
+
"Must have atleast one ai request to be processed"
|
|
164
|
+
)
|
|
165
|
+
# not optimal, but so far, recreating the list and dropping the internal store.
|
|
166
|
+
# seems straight forward
|
|
167
|
+
queries = self.queries[:]
|
|
168
|
+
server_query = ai_query.AIServerQuery(queries=queries, trace_id=self.tracing_id)
|
|
169
|
+
self.drop()
|
|
170
|
+
return server_query
|
|
171
|
+
|
|
172
|
+
def exec(self) -> ai_response.AIServerResult:
|
|
173
|
+
"""Executes a pipelined request"""
|
|
174
|
+
return self.client.process_request(message=self.to_server_query())
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from ahnlich_client_py import exceptions as ah_exceptions
|
|
4
|
+
from ahnlich_client_py.internals import db_query, db_response
|
|
5
|
+
from ahnlich_client_py.internals import serde_types as st
|
|
6
|
+
from ahnlich_client_py.internals.base_client import BaseClient
|
|
7
|
+
from ahnlich_client_py.libs import NonZeroSizeInteger
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AhnlichDBRequestBuilder:
|
|
11
|
+
def __init__(self, tracing_id: str = None, client: BaseClient = None) -> None:
|
|
12
|
+
self.queries: typing.List[db_query.Query] = []
|
|
13
|
+
self.tracing_id = tracing_id
|
|
14
|
+
self.client: BaseClient = client
|
|
15
|
+
|
|
16
|
+
def create_store(
|
|
17
|
+
self,
|
|
18
|
+
store_name: str,
|
|
19
|
+
dimension: st.uint64,
|
|
20
|
+
create_predicates: typing.Sequence[str] = None,
|
|
21
|
+
non_linear_indices: typing.Sequence[db_query.NonLinearAlgorithm] = None,
|
|
22
|
+
error_if_exists: bool = True,
|
|
23
|
+
):
|
|
24
|
+
if not create_predicates:
|
|
25
|
+
create_predicates = []
|
|
26
|
+
if not non_linear_indices:
|
|
27
|
+
non_linear_indices = []
|
|
28
|
+
|
|
29
|
+
non_zero = NonZeroSizeInteger(num=dimension)
|
|
30
|
+
self.queries.append(
|
|
31
|
+
db_query.Query__CreateStore(
|
|
32
|
+
store=store_name,
|
|
33
|
+
dimension=non_zero.value,
|
|
34
|
+
create_predicates=create_predicates,
|
|
35
|
+
non_linear_indices=non_linear_indices,
|
|
36
|
+
error_if_exists=error_if_exists,
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def get_key(self, store_name: str, keys: typing.Sequence[db_query.Array]):
|
|
41
|
+
self.queries.append(db_query.Query__GetKey(store=store_name, keys=keys))
|
|
42
|
+
|
|
43
|
+
def get_by_predicate(self, store_name: str, condition: db_query.PredicateCondition):
|
|
44
|
+
self.queries.append(
|
|
45
|
+
db_query.Query__GetPred(store=store_name, condition=condition)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def get_sim_n(
|
|
49
|
+
self,
|
|
50
|
+
store_name: str,
|
|
51
|
+
search_input: db_query.Array,
|
|
52
|
+
closest_n: st.uint64 = 1,
|
|
53
|
+
algorithm: db_query.Algorithm = db_query.Algorithm__CosineSimilarity,
|
|
54
|
+
condition: db_query.PredicateCondition = None,
|
|
55
|
+
):
|
|
56
|
+
nonzero = NonZeroSizeInteger(closest_n)
|
|
57
|
+
self.queries.append(
|
|
58
|
+
db_query.Query__GetSimN(
|
|
59
|
+
store=store_name,
|
|
60
|
+
search_input=search_input,
|
|
61
|
+
closest_n=nonzero.value,
|
|
62
|
+
algorithm=algorithm,
|
|
63
|
+
condition=condition,
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
def create_pred_index(self, store_name: str, predicates: typing.Sequence[str]):
|
|
68
|
+
self.queries.append(
|
|
69
|
+
db_query.Query__CreatePredIndex(store=store_name, predicates=predicates)
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
def create_non_linear_algorithm_index(
|
|
73
|
+
self, store_name: str, non_linear_indices: typing.Sequence["NonLinearAlgorithm"]
|
|
74
|
+
):
|
|
75
|
+
self.queries.append(
|
|
76
|
+
db_query.Query__CreateNonLinearAlgorithmIndex(
|
|
77
|
+
store=store_name, non_linear_indices=non_linear_indices
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
def drop_pred_index(
|
|
82
|
+
self,
|
|
83
|
+
store_name: str,
|
|
84
|
+
predicates: typing.Sequence[str],
|
|
85
|
+
error_if_not_exists: bool = True,
|
|
86
|
+
):
|
|
87
|
+
self.queries.append(
|
|
88
|
+
db_query.Query__DropPredIndex(
|
|
89
|
+
store=store_name,
|
|
90
|
+
predicates=predicates,
|
|
91
|
+
error_if_not_exists=error_if_not_exists,
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
def drop_non_linear_algorithm_index(
|
|
96
|
+
self,
|
|
97
|
+
store_name: str,
|
|
98
|
+
non_linear_indices: typing.Sequence["NonLinearAlgorithm"],
|
|
99
|
+
error_if_not_exists: bool = True,
|
|
100
|
+
):
|
|
101
|
+
self.queries.append(
|
|
102
|
+
db_query.Query__DropNonLinearAlgorithmIndex(
|
|
103
|
+
store=store_name,
|
|
104
|
+
non_linear_indices=non_linear_indices,
|
|
105
|
+
error_if_not_exists=error_if_not_exists,
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
def set(
|
|
110
|
+
self,
|
|
111
|
+
store_name,
|
|
112
|
+
inputs: typing.Sequence[
|
|
113
|
+
typing.Tuple[db_query.Array, typing.Dict[str, db_query.MetadataValue]]
|
|
114
|
+
],
|
|
115
|
+
):
|
|
116
|
+
self.queries.append(db_query.Query__Set(store=store_name, inputs=inputs))
|
|
117
|
+
|
|
118
|
+
def delete_key(self, store_name: str, keys: typing.Sequence[db_query.Array]):
|
|
119
|
+
self.queries.append(db_query.Query__DelKey(store=store_name, keys=keys))
|
|
120
|
+
|
|
121
|
+
def delete_predicate(self, store_name: str, condition: db_query.PredicateCondition):
|
|
122
|
+
self.queries.append(
|
|
123
|
+
db_query.Query__DelPred(store=store_name, condition=condition)
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
def drop_store(self, store_name: str, error_if_not_exists: bool = True):
|
|
127
|
+
self.queries.append(
|
|
128
|
+
db_query.Query__DropStore(
|
|
129
|
+
store=store_name, error_if_not_exists=error_if_not_exists
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
def list_stores(self):
|
|
134
|
+
self.queries.append(db_query.Query__ListStores())
|
|
135
|
+
|
|
136
|
+
def info_server(self):
|
|
137
|
+
self.queries.append(db_query.Query__InfoServer())
|
|
138
|
+
|
|
139
|
+
def list_clients(self):
|
|
140
|
+
self.queries.append(db_query.Query__ListClients())
|
|
141
|
+
|
|
142
|
+
def ping(self):
|
|
143
|
+
self.queries.append(db_query.Query__Ping())
|
|
144
|
+
|
|
145
|
+
def drop(self):
|
|
146
|
+
self.queries.clear()
|
|
147
|
+
|
|
148
|
+
def to_server_query(self) -> db_query.ServerQuery:
|
|
149
|
+
if not self.queries:
|
|
150
|
+
raise ah_exceptions.AhnlichClientException(
|
|
151
|
+
"Must have atleast one request to be processed"
|
|
152
|
+
)
|
|
153
|
+
# not optimal, but so far, recreating the list and dropping the internal store.
|
|
154
|
+
# seems straight forward
|
|
155
|
+
queries = self.queries[:]
|
|
156
|
+
|
|
157
|
+
server_query = db_query.ServerQuery(queries=queries, trace_id=self.tracing_id)
|
|
158
|
+
self.drop()
|
|
159
|
+
return server_query
|
|
160
|
+
|
|
161
|
+
def exec(self) -> db_response.ServerResult:
|
|
162
|
+
"""Executes a pipelined request"""
|
|
163
|
+
return self.client.process_request(message=self.to_server_query())
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from ahnlich_client_py.builders import AhnlichAIRequestBuilder
|
|
4
|
+
from ahnlich_client_py.internals import ai_query, ai_response
|
|
5
|
+
from ahnlich_client_py.internals.async_base_client import BaseClient
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AsyncAhnlichAIRequestBuilder(AhnlichAIRequestBuilder):
|
|
9
|
+
def __init__(self, tracing_id: str = None, client: BaseClient = None) -> None:
|
|
10
|
+
self.queries: typing.List[ai_query.AIQuery] = []
|
|
11
|
+
self.tracing_id = tracing_id
|
|
12
|
+
self.client: BaseClient = client
|
|
13
|
+
|
|
14
|
+
async def exec(self) -> ai_response.AIServerResult:
|
|
15
|
+
"""Executes a pipelined request"""
|
|
16
|
+
return await self.client.process_request(message=self.to_server_query())
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from ahnlich_client_py.builders import AhnlichDBRequestBuilder
|
|
4
|
+
from ahnlich_client_py.internals import db_query, db_response
|
|
5
|
+
from ahnlich_client_py.internals.async_base_client import BaseClient
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AsyncAhnlichDBRequestBuilder(AhnlichDBRequestBuilder):
|
|
9
|
+
def __init__(self, tracing_id: str = None, client: BaseClient = None) -> None:
|
|
10
|
+
self.queries: typing.List[db_query.Query] = []
|
|
11
|
+
self.tracing_id = tracing_id
|
|
12
|
+
self.client: BaseClient = client
|
|
13
|
+
|
|
14
|
+
async def exec(self) -> db_response.ServerResult:
|
|
15
|
+
"""Executes a pipelined request"""
|
|
16
|
+
return await self.client.process_request(message=self.to_server_query())
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from ahnlich_client_py import builders
|
|
4
|
+
from ahnlich_client_py.config import AhnlichPoolSettings
|
|
5
|
+
from ahnlich_client_py.internals import ai_query, ai_response
|
|
6
|
+
from ahnlich_client_py.internals import serde_types as st
|
|
7
|
+
from ahnlich_client_py.internals.base_client import BaseClient
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AhnlichAIClient(BaseClient):
|
|
11
|
+
"""Wrapper for interacting with Ahnlich AI Proxy"""
|
|
12
|
+
|
|
13
|
+
def __init__(
|
|
14
|
+
self,
|
|
15
|
+
address: str,
|
|
16
|
+
port: int,
|
|
17
|
+
connect_timeout_sec: float = 5.0,
|
|
18
|
+
pool_settings: AhnlichPoolSettings = AhnlichPoolSettings(),
|
|
19
|
+
) -> None:
|
|
20
|
+
super().__init__(
|
|
21
|
+
address=address,
|
|
22
|
+
port=port,
|
|
23
|
+
connect_timeout_sec=connect_timeout_sec,
|
|
24
|
+
pool_settings=pool_settings,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
def get_response_class(self):
|
|
28
|
+
return ai_response.AIServerResult
|
|
29
|
+
|
|
30
|
+
def create_store(
|
|
31
|
+
self,
|
|
32
|
+
store_name: str,
|
|
33
|
+
query_model: ai_query.AIModel,
|
|
34
|
+
index_model: ai_query.AIModel,
|
|
35
|
+
predicates: typing.Sequence[str] = None,
|
|
36
|
+
non_linear_indices: typing.Sequence[ai_query.NonLinearAlgorithm] = None,
|
|
37
|
+
error_if_exists: bool = True,
|
|
38
|
+
tracing_id: typing.Optional[str] = None,
|
|
39
|
+
):
|
|
40
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
41
|
+
builder.create_store(
|
|
42
|
+
store_name=store_name,
|
|
43
|
+
query_model=query_model,
|
|
44
|
+
index_model=index_model,
|
|
45
|
+
predicates=predicates,
|
|
46
|
+
non_linear_indices=non_linear_indices,
|
|
47
|
+
error_if_exists=error_if_exists,
|
|
48
|
+
)
|
|
49
|
+
return self.process_request(builder.to_server_query())
|
|
50
|
+
|
|
51
|
+
def get_pred(
|
|
52
|
+
self,
|
|
53
|
+
store_name: str,
|
|
54
|
+
condition: ai_query.PredicateCondition,
|
|
55
|
+
tracing_id: typing.Optional[str] = None,
|
|
56
|
+
):
|
|
57
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
58
|
+
builder.get_pred(store_name=store_name, condition=condition)
|
|
59
|
+
return self.process_request(builder.to_server_query())
|
|
60
|
+
|
|
61
|
+
def get_sim_n(
|
|
62
|
+
self,
|
|
63
|
+
store_name: str,
|
|
64
|
+
search_input: ai_query.StoreInput,
|
|
65
|
+
closest_n: st.uint64,
|
|
66
|
+
algorithm: ai_query.Algorithm,
|
|
67
|
+
condition: typing.Optional[ai_query.PredicateCondition] = None,
|
|
68
|
+
tracing_id: typing.Optional[str] = None,
|
|
69
|
+
):
|
|
70
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
71
|
+
builder.get_sim_n(
|
|
72
|
+
store_name=store_name,
|
|
73
|
+
search_input=search_input,
|
|
74
|
+
closest_n=closest_n,
|
|
75
|
+
algorithm=algorithm,
|
|
76
|
+
condition=condition,
|
|
77
|
+
)
|
|
78
|
+
return self.process_request(builder.to_server_query())
|
|
79
|
+
|
|
80
|
+
def create_pred_index(
|
|
81
|
+
self,
|
|
82
|
+
store_name: str,
|
|
83
|
+
predicates: typing.Sequence[str],
|
|
84
|
+
tracing_id: typing.Optional[str] = None,
|
|
85
|
+
):
|
|
86
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
87
|
+
builder.create_pred_index(store_name=store_name, predicates=predicates)
|
|
88
|
+
return self.process_request(builder.to_server_query())
|
|
89
|
+
|
|
90
|
+
def create_non_linear_algorithm_index(
|
|
91
|
+
self,
|
|
92
|
+
store_name: str,
|
|
93
|
+
non_linear_indices: typing.Sequence["NonLinearAlgorithm"],
|
|
94
|
+
tracing_id: typing.Optional[str] = None,
|
|
95
|
+
):
|
|
96
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
97
|
+
builder.create_non_linear_algorithm_index(
|
|
98
|
+
store_name=store_name, non_linear_indices=non_linear_indices
|
|
99
|
+
)
|
|
100
|
+
return self.process_request(builder.to_server_query())
|
|
101
|
+
|
|
102
|
+
def drop_pred_index(
|
|
103
|
+
self,
|
|
104
|
+
store_name: str,
|
|
105
|
+
predicates: typing.Sequence[str],
|
|
106
|
+
error_if_not_exists: bool,
|
|
107
|
+
tracing_id: typing.Optional[str] = None,
|
|
108
|
+
):
|
|
109
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
110
|
+
builder.drop_pred_index(
|
|
111
|
+
store_name=store_name,
|
|
112
|
+
predicates=predicates,
|
|
113
|
+
error_if_not_exists=error_if_not_exists,
|
|
114
|
+
)
|
|
115
|
+
return self.process_request(builder.to_server_query())
|
|
116
|
+
|
|
117
|
+
def drop_non_linear_algorithm_index(
|
|
118
|
+
self,
|
|
119
|
+
store_name: str,
|
|
120
|
+
non_linear_indices: typing.Sequence["NonLinearAlgorithm"],
|
|
121
|
+
error_if_not_exists: bool,
|
|
122
|
+
tracing_id: typing.Optional[str] = None,
|
|
123
|
+
):
|
|
124
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
125
|
+
builder.drop_non_linear_algorithm_index()(
|
|
126
|
+
store_name=store_name,
|
|
127
|
+
non_linear_indices=non_linear_indices,
|
|
128
|
+
error_if_not_exists=error_if_not_exists,
|
|
129
|
+
)
|
|
130
|
+
return self.process_request(builder.to_server_query())
|
|
131
|
+
|
|
132
|
+
def set(
|
|
133
|
+
self,
|
|
134
|
+
store_name: str,
|
|
135
|
+
inputs: typing.Sequence[
|
|
136
|
+
typing.Tuple[ai_query.StoreInput, typing.Dict[str, ai_query.MetadataValue]]
|
|
137
|
+
],
|
|
138
|
+
preprocess_action=ai_query.PreprocessAction,
|
|
139
|
+
tracing_id: typing.Optional[str] = None,
|
|
140
|
+
):
|
|
141
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
142
|
+
builder.set(
|
|
143
|
+
store_name=store_name, inputs=inputs, preprocess_action=preprocess_action
|
|
144
|
+
)
|
|
145
|
+
return self.process_request(builder.to_server_query())
|
|
146
|
+
|
|
147
|
+
def del_key(
|
|
148
|
+
self,
|
|
149
|
+
store_name: str,
|
|
150
|
+
key: ai_query.StoreInput,
|
|
151
|
+
tracing_id: typing.Optional[str] = None,
|
|
152
|
+
):
|
|
153
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
154
|
+
builder.del_key(store_name=store_name, key=key)
|
|
155
|
+
return self.process_request(builder.to_server_query())
|
|
156
|
+
|
|
157
|
+
def get_key(
|
|
158
|
+
self,
|
|
159
|
+
store_name: str,
|
|
160
|
+
keys: typing.Sequence[ai_query.StoreInput],
|
|
161
|
+
tracing_id: typing.Optional[str] = None,
|
|
162
|
+
):
|
|
163
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
164
|
+
builder.get_key(store_name=store_name, keys=keys)
|
|
165
|
+
return self.process_request(builder.to_server_query())
|
|
166
|
+
|
|
167
|
+
def drop_store(
|
|
168
|
+
self,
|
|
169
|
+
store_name: str,
|
|
170
|
+
error_if_not_exists: bool,
|
|
171
|
+
tracing_id: typing.Optional[str] = None,
|
|
172
|
+
):
|
|
173
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
174
|
+
builder.drop_store(
|
|
175
|
+
store_name=store_name, error_if_not_exists=error_if_not_exists
|
|
176
|
+
)
|
|
177
|
+
return self.process_request(builder.to_server_query())
|
|
178
|
+
|
|
179
|
+
def purge_stores(
|
|
180
|
+
self,
|
|
181
|
+
tracing_id: typing.Optional[str] = None,
|
|
182
|
+
):
|
|
183
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
184
|
+
builder.purge_stores()
|
|
185
|
+
return self.process_request(builder.to_server_query())
|
|
186
|
+
|
|
187
|
+
def info_server(
|
|
188
|
+
self,
|
|
189
|
+
tracing_id: typing.Optional[str] = None,
|
|
190
|
+
):
|
|
191
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
192
|
+
builder.info_server()
|
|
193
|
+
return self.process_request(builder.to_server_query())
|
|
194
|
+
|
|
195
|
+
def list_stores(
|
|
196
|
+
self,
|
|
197
|
+
tracing_id: typing.Optional[str] = None,
|
|
198
|
+
):
|
|
199
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
200
|
+
builder.list_stores()
|
|
201
|
+
return self.process_request(builder.to_server_query())
|
|
202
|
+
|
|
203
|
+
def list_clients(
|
|
204
|
+
self,
|
|
205
|
+
tracing_id: typing.Optional[str] = None,
|
|
206
|
+
):
|
|
207
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
208
|
+
builder.list_clients()
|
|
209
|
+
return self.process_request(builder.to_server_query())
|
|
210
|
+
|
|
211
|
+
def ping(
|
|
212
|
+
self,
|
|
213
|
+
tracing_id: typing.Optional[str] = None,
|
|
214
|
+
):
|
|
215
|
+
builder = builders.AhnlichAIRequestBuilder(tracing_id)
|
|
216
|
+
builder.ping()
|
|
217
|
+
return self.process_request(builder.to_server_query())
|
|
218
|
+
|
|
219
|
+
def pipeline(
|
|
220
|
+
self,
|
|
221
|
+
tracing_id: typing.Optional[str] = None,
|
|
222
|
+
) -> builders.AhnlichAIRequestBuilder:
|
|
223
|
+
"""Gives you a request builder to create multple requests"""
|
|
224
|
+
return builders.AhnlichAIRequestBuilder(tracing_id, client=self)
|