sunholo 0.83.3__py3-none-any.whl → 0.83.5__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.
@@ -9,6 +9,7 @@ except ImportError:
9
9
  pass
10
10
 
11
11
  from .database import get_vector_size
12
+ from .uuid import generate_uuid_from_object_id
12
13
  from ..custom_logging import log
13
14
  from ..utils import ConfigManager
14
15
 
@@ -79,9 +80,11 @@ class AlloyDBClient:
79
80
  log.info("User specified {user} - using pg8000 engine")
80
81
  self.inst_url = self._build_instance_uri(project_id, region, cluster_name, instance_name)
81
82
  self.engine = self._create_engine_from_pg8000()
83
+ self.engine_type = "pg8000"
82
84
  else:
83
85
  log.info("Build with Langchain engine - will use default service account for auth")
84
86
  self.engine = self._create_engine()
87
+ self.engine_type = "langchain"
85
88
 
86
89
  def _build_instance_uri(self, project_id, region, cluster_name, instance_name):
87
90
  return f"projects/{project_id}/locations/{region}/clusters/{cluster_name}/instances/{instance_name}"
@@ -120,16 +123,25 @@ class AlloyDBClient:
120
123
  region=self.config["region"],
121
124
  cluster=self.config["cluster"],
122
125
  instance=self.config["instance"],
123
- password=self.password,
124
126
  database=self.database,
125
127
  ip_type=self.config.get("ip_type") or IPTypes.PRIVATE
126
128
  )
129
+ self._loop = engine._loop
127
130
 
128
131
  log.info(f"Created AlloyDB engine for {engine}")
129
132
 
130
133
  return engine
131
-
134
+
132
135
  def execute_sql(self, sql_statement):
136
+ if self.engine_type == "pg8000":
137
+ return self._execute_sql_pg8000(sql_statement)
138
+ elif self.engine_type == "langchain":
139
+ return self._execute_sql_langchain(sql_statement)
140
+
141
+ def _execute_sql_langchain(self, sql_statement):
142
+ return self.engine._fetch(query = sql_statement)
143
+
144
+ def _execute_sql_pg8000(self, sql_statement):
133
145
  """Executes a given SQL statement with error handling.
134
146
 
135
147
  - sql_statement (str): The SQL statement to execute.
@@ -152,6 +164,17 @@ class AlloyDBClient:
152
164
  return result
153
165
 
154
166
  async def execute_sql_async(self, sql_statement):
167
+ if self.engine_type == "pg8000":
168
+ result = await self._execute_sql_async_pg8000(sql_statement)
169
+ elif self.engine_type == "langchain":
170
+ result = await self._execute_sql_async_langchain(sql_statement)
171
+
172
+ return result
173
+
174
+ async def _execute_sql_async_langchain(self, sql_statement):
175
+ return await self.engine._afetch(query = sql_statement)
176
+
177
+ async def _execute_sql_async_pg8000(self, sql_statement):
155
178
  """Executes a given SQL statement asynchronously with error handling."""
156
179
  sql_ = sqlalchemy.text(sql_statement)
157
180
  result = None
@@ -168,6 +191,34 @@ class AlloyDBClient:
168
191
  await conn.close()
169
192
 
170
193
  return result
194
+
195
+ def get_document_from_docstore(self, source:str, vector_name):
196
+ query = self._get_document_from_docstore(source, vector_name)
197
+
198
+ return self.execute_sql(query)
199
+
200
+ async def get_document_from_docstore_async(self, source:str, vector_name:str):
201
+ query = self._get_document_from_docstore(source, vector_name)
202
+
203
+ document = await self.execute_sql_async(query)
204
+
205
+ return document
206
+
207
+ def _get_document_from_docstore(self, source:str, vector_name:str):
208
+ if not isinstance(source, str):
209
+ raise ValueError("The 'source' parameter must be a single string, not a list of strings or other iterable.")
210
+
211
+ table_name = f"{vector_name}_docstore"
212
+ doc_id = generate_uuid_from_object_id(source)
213
+
214
+ query = f"""
215
+ SELECT *
216
+ FROM {table_name}
217
+ WHERE doc_id = {doc_id}
218
+ LIMIT 1;
219
+ """
220
+
221
+ return query
171
222
 
172
223
  async def get_sources_from_docstore_async(self, sources, vector_name, search_type="OR", just_source_name=False):
173
224
  """Fetches sources from the docstore asynchronously."""
@@ -211,7 +262,7 @@ class AlloyDBClient:
211
262
  FROM {table_name}
212
263
  WHERE {conditions}
213
264
  ORDER BY langchain_metadata->>'objectId' ASC
214
- LIMIT 500;
265
+ LIMIT 50;
215
266
  """
216
267
 
217
268
  return query
@@ -89,7 +89,7 @@ class ConfigManager:
89
89
  continue
90
90
  if filename.endswith(('.yaml', '.yml', '.json')):
91
91
  config_file = os.path.join(folder, filename)
92
- log.debug(f"Checking config file: {config_file}")
92
+
93
93
  if filename in self.config_cache:
94
94
  cached_config, cache_time = self.config_cache[filename]
95
95
  time_to_recache = (current_time - cache_time)
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.83.3
3
+ Version: 0.83.5
4
4
  Summary: Large Language Model DevOps - a package to help deploy LLMs to the Cloud.
5
5
  Home-page: https://github.com/sunholo-data/sunholo-py
6
- Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.83.3.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.83.5.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0
@@ -21,7 +21,7 @@ License-File: LICENSE.txt
21
21
  Requires-Dist: google-auth
22
22
  Requires-Dist: ruamel.yaml
23
23
  Requires-Dist: langchain >=0.2.12
24
- Requires-Dist: langchain-experimental >=0.0.61
24
+ Requires-Dist: langchain-experimental ==0.0.63
25
25
  Requires-Dist: langchain-community >=0.2.11
26
26
  Provides-Extra: all
27
27
  Requires-Dist: asyncpg ; extra == 'all'
@@ -59,7 +59,7 @@ sunholo/components/retriever.py,sha256=bKIVT7_18Ut3OJd0E0jyiISPnD9qkHWVjcQPT4i1_
59
59
  sunholo/components/vectorstore.py,sha256=xKk7micTRwZckaI7U6PxvFz_ZSjCH48xPTDYiDcv2tc,5913
60
60
  sunholo/database/__init__.py,sha256=bpB5Nk21kwqYj-qdVnvNgXjLsbflnH4g-San7OHMqR4,283
61
61
  sunholo/database/alloydb.py,sha256=YH8wNPS8gN-TDZEXQcVHxwd1NScHRfAxma3gK4R6KCk,11740
62
- sunholo/database/alloydb_client.py,sha256=138gtbPzgcFT9j6hLQ1QD263ny_wJ0qPXCjKIK49Xts,12722
62
+ sunholo/database/alloydb_client.py,sha256=JYozFOOdeDNEB1D2_If488qS1Qc7emHowUEQL0fgU1E,14617
63
63
  sunholo/database/database.py,sha256=VqhZdkXUNdvWn8sUcUV3YNby1JDVf7IykPVXWBtxo9U,7361
64
64
  sunholo/database/lancedb.py,sha256=DyfZntiFKBlVPaFooNN1Z6Pl-LAs4nxWKKuq8GBqN58,715
65
65
  sunholo/database/static_dbs.py,sha256=8cvcMwUK6c32AS2e_WguKXWMkFf5iN3g9WHzsh0C07Q,442
@@ -118,7 +118,7 @@ sunholo/utils/__init__.py,sha256=Hv02T5L2zYWvCso5hzzwm8FQogwBq0OgtUbN_7Quzqc,89
118
118
  sunholo/utils/api_key.py,sha256=Ct4bIAQZxzPEw14hP586LpVxBAVi_W9Serpy0BK-7KI,244
119
119
  sunholo/utils/big_context.py,sha256=gJIP7_ZL-YSLhOMq8jmFTMqH1wq8eB1NK7oKPeZAq2s,5578
120
120
  sunholo/utils/config.py,sha256=aG29MXcL5qzQMtCMqcdy-2ysDCYf9Zn_ZLk5NNOQNSE,8982
121
- sunholo/utils/config_class.py,sha256=ygKw3E-Q6MLc1XZKRULCTPTibsOFlEfyCA3GyxOhPa8,9869
121
+ sunholo/utils/config_class.py,sha256=tp3mXrwbgOISvI1iT-NhEffD6QpIUK65ik7aT_gi-5o,9819
122
122
  sunholo/utils/config_schema.py,sha256=Wv-ncitzljOhgbDaq9qnFqH5LCuxNv59dTGDWgd1qdk,4189
123
123
  sunholo/utils/gcp.py,sha256=uueODEpA-P6O15-t0hmcGC9dONLO_hLfzSsSoQnkUss,4854
124
124
  sunholo/utils/gcp_project.py,sha256=Fa0IhCX12bZ1ctF_PKN8PNYd7hihEUfb90kilBfUDjg,1411
@@ -134,9 +134,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
134
134
  sunholo/vertex/memory_tools.py,sha256=q_phxgGX2TG2j2MXNULF2xGzQnQPENwjPN9nZ_A9Gh0,7526
135
135
  sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
136
136
  sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
137
- sunholo-0.83.3.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
138
- sunholo-0.83.3.dist-info/METADATA,sha256=SIKK5jlQKCKbpXixBWG5EJZiU_BUku1ytzEbiz0tnWE,7413
139
- sunholo-0.83.3.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
140
- sunholo-0.83.3.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
141
- sunholo-0.83.3.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
142
- sunholo-0.83.3.dist-info/RECORD,,
137
+ sunholo-0.83.5.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
138
+ sunholo-0.83.5.dist-info/METADATA,sha256=05IvbTEGbeGoW5dwFBd2IUAEBd7nFySYZcQConfSrLs,7413
139
+ sunholo-0.83.5.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
140
+ sunholo-0.83.5.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
141
+ sunholo-0.83.5.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
142
+ sunholo-0.83.5.dist-info/RECORD,,