sunholo 0.90.6__py3-none-any.whl → 0.91.1__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.
@@ -3,7 +3,7 @@ try:
3
3
  import pg8000
4
4
  import sqlalchemy
5
5
  from sqlalchemy.exc import DatabaseError, ProgrammingError
6
- from langchain_google_alloydb_pg import AlloyDBEngine
6
+ from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBVectorStore
7
7
  except ImportError:
8
8
  AlloyDBEngine = None
9
9
  pass
@@ -12,6 +12,7 @@ from .database import get_vector_size
12
12
  from .uuid import generate_uuid_from_object_id
13
13
  from ..custom_logging import log
14
14
  from ..utils import ConfigManager
15
+ from ..components import get_embeddings
15
16
 
16
17
  class AlloyDBClient:
17
18
  """
@@ -62,6 +63,7 @@ class AlloyDBClient:
62
63
  if not alloydb_config:
63
64
  raise ValueError("Must specify vac.alloydb_config")
64
65
  self.config = alloydb_config
66
+ self.vector_name = self.config.get("vac")
65
67
  project_id = alloydb_config["project_id"]
66
68
  region = alloydb_config["region"]
67
69
  cluster_name = alloydb_config["cluster"]
@@ -87,6 +89,11 @@ class AlloyDBClient:
87
89
  log.info("Build with Langchain engine - will use default service account for auth")
88
90
  self.engine = self._create_engine()
89
91
  self.engine_type = "langchain"
92
+
93
+ if self.engine_type == "langchain":
94
+ self.vectorstore = self.get_vectorstore()
95
+ else:
96
+ self.vectorstore = None
90
97
 
91
98
  def _build_instance_uri(self, project_id, region, cluster_name, instance_name):
92
99
  return f"projects/{project_id}/locations/{region}/clusters/{cluster_name}/instances/{instance_name}"
@@ -134,6 +141,52 @@ class AlloyDBClient:
134
141
 
135
142
  return engine
136
143
 
144
+ def _get_embedder(self):
145
+ return get_embeddings(self.vector_name)
146
+
147
+ def get_vectorstore(self):
148
+ if self.engine_type != "langchain":
149
+ raise ValueError("Not available using pg8000 engine")
150
+
151
+ if self.vector_name is None:
152
+ raise ValueError("No vectorname found - init with ConfigManager?")
153
+
154
+ vector_size = get_vector_size(self.vector_name)
155
+ table_name = f"{self.vector_name}_vectorstore_{vector_size}"
156
+
157
+ log.info(f"Initialised AlloyDBClient with AlloyDBVectorStore: {table_name}")
158
+ self.vectorstore = AlloyDBVectorStore.create_sync(
159
+ engine=self.engine,
160
+ table_name=table_name,
161
+ embedding_service=self._get_embedder(),
162
+ metadata_columns=["source", "docstore_doc_id"]
163
+ #metadata_columns=["source", "eventTime"]
164
+ )
165
+
166
+ return self.vectorstore
167
+
168
+ def _similarity_search(self, query, source_filter:str="", free_filter:str=None):
169
+
170
+ if free_filter is None:
171
+ source_filter_cmd = f"source %LIKE% {source_filter}" if source_filter else None
172
+ else:
173
+ source_filter_cmd = free_filter
174
+
175
+ log.info(f"Similarity search for {query} and {source_filter_cmd}")
176
+
177
+ return query, source_filter_cmd
178
+
179
+ def similarity_search(self, query:str, source_filter:str="", free_filter:str=None, k:int=5):
180
+
181
+ query, source_filter_cmd = self._similarity_search(query, source_filter, free_filter)
182
+
183
+ return self.vectorstore.similarity_search(query, filter=source_filter_cmd, k=k)
184
+
185
+ async def asimilarity_search(self, query:str, source_filter:str="", free_filter:str=None, k:int=5):
186
+ query, source_filter_cmd = self._similarity_search(query, source_filter, free_filter)
187
+
188
+ return await self.vectorstore.asimilarity_search(query, filter=source_filter_cmd, k=k)
189
+
137
190
  def execute_sql(self, sql_statement):
138
191
  if self.engine_type == "pg8000":
139
192
  return self._execute_sql_pg8000(sql_statement)
@@ -178,6 +178,8 @@ class LlamaIndexVertexCorpusManager:
178
178
 
179
179
  def query_corpus(self, query:str, corpus_disply_name:str):
180
180
  corpus = self.find_corpus_from_list(corpus_disply_name)
181
+
182
+ log.info(f"Querying {corpus.name=} with {query=}")
181
183
 
182
184
  response:RetrieveContextsResponse = rag.retrieval_query(
183
185
  rag_resources=[
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.90.6
3
+ Version: 0.91.1
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.90.6.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.91.1.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0
@@ -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=H2BfucbMOm1nT6Pq6MS1Yw4ZIG02KKKTeOijX8B6DaU,14804
62
+ sunholo/database/alloydb_client.py,sha256=urXmesN-41FrjmYIy1ybp7zUdw7Y4UnVUhWDacBELAU,17002
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
@@ -99,7 +99,7 @@ sunholo/langfuse/prompts.py,sha256=27BsVfihM6-h1jscbkGSO4HsATl-d4ZN6tcNCVztWoY,1
99
99
  sunholo/llamaindex/__init__.py,sha256=DlY_cHWCsVEV1C5WBgDdHRgOMlJc8pDoCRukUJ8PT9w,88
100
100
  sunholo/llamaindex/get_files.py,sha256=6rhXCDqQ_lrIapISQ_OYQDjiSATXvS_9m3qq53-oIl0,781
101
101
  sunholo/llamaindex/import_files.py,sha256=Bnic5wz8c61af9Kwq8KSrNBbc4imYnzMtBCb2jzSImI,6224
102
- sunholo/llamaindex/llamaindex_class.py,sha256=wtMS97YMsfA2IWLTd5mzr73DV4_fi5I5GVD7AC4wVm0,17375
102
+ sunholo/llamaindex/llamaindex_class.py,sha256=PnpPoc7LpP7xvKIXYu-UvI4ehj67pGhE1EIWEQyimhQ,17435
103
103
  sunholo/llamaindex/user_history.py,sha256=ZtkecWuF9ORduyGB8kF8gP66bm9DdvCI-ZiK6Kt-cSE,2265
104
104
  sunholo/lookup/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
105
105
  sunholo/lookup/model_lookup.yaml,sha256=O7o-jP53MLA06C8pI-ILwERShO-xf6z_258wtpZBv6A,739
@@ -144,9 +144,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
144
144
  sunholo/vertex/memory_tools.py,sha256=q_phxgGX2TG2j2MXNULF2xGzQnQPENwjPN9nZ_A9Gh0,7526
145
145
  sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
146
146
  sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
147
- sunholo-0.90.6.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
148
- sunholo-0.90.6.dist-info/METADATA,sha256=oeL4J2tqfAvbatVNoApFgnG2_1A2mN3lpeoVZmLFhdE,7806
149
- sunholo-0.90.6.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
150
- sunholo-0.90.6.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
151
- sunholo-0.90.6.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
152
- sunholo-0.90.6.dist-info/RECORD,,
147
+ sunholo-0.91.1.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
148
+ sunholo-0.91.1.dist-info/METADATA,sha256=VV2CVfBHDRqyFrsgGDzyd-xfFC8gOGn9LTZvuDwjO0Y,7806
149
+ sunholo-0.91.1.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
150
+ sunholo-0.91.1.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
151
+ sunholo-0.91.1.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
152
+ sunholo-0.91.1.dist-info/RECORD,,