Skip to content

Commit

Permalink
project resolution for ai search
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEdmondson1234 committed Nov 14, 2024
1 parent 67e5b09 commit bbec900
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

version = '0.109.6'
version = '0.110.0'

setup(
name='sunholo',
Expand Down
10 changes: 9 additions & 1 deletion sunholo/discovery_engine/chunker_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ def do_discovery_engine(message_data:str, metadata:dict, config:ConfigManager=No
log.info(f"Found vectorstore {vectorstore}")
if value.get('read_only'):
continue
gcp_config = config.vacConfig("gcp_config")
if not gcp_config:
project_id = get_gcp_project()
else:
project_id = gcp_config.get("project_id")

if not project_id:
raise ValueError("Couldn't retrieve project_id for vertex_ai_search")
#location = gcp_config.get('location')
corpus = DiscoveryEngineClient(
data_store_id=config.vector_name,
project_id=get_gcp_project(),
project_id=project_id
# location needs to be 'eu' or 'us' which doesn't work with other configurations
#location=location or global_location
)
Expand Down
3 changes: 2 additions & 1 deletion sunholo/discovery_engine/create_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def create_new_discovery_engine(config:ConfigManager):
if "chunk_size" in chunker_config:
chunk_size = chunker_config["chunk_size"]

project_id = get_gcp_project()
gcp_config = config.vacConfig("gcp_config")
project_id = gcp_config.get("project_id") or get_gcp_project()
if not project_id:
raise ValueError("Could not find project_id in gcp_config")

Expand Down
10 changes: 7 additions & 3 deletions sunholo/discovery_engine/get_ai_search_chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def get_all_chunks(question:str, config:ConfigManager):
num_chunks = value.get('num_chunks') or 3
gcp_config = config.vacConfig("gcp_config")
project_id = gcp_config.get('project_id')
chunk = get_chunks(question, vector_name, num_chunks, project_id=project_id)
serving_config = value.get('serving_config')

chunk = get_chunks(question, vector_name, num_chunks, project_id=project_id, serving_config=serving_config)
if chunk:
chunks.append(chunk)
if chunks:
Expand All @@ -46,10 +48,12 @@ def get_all_chunks(question:str, config:ConfigManager):
log.warning(f"No chunks found for {vector_name}")
return None

def get_chunks(question, vector_name, num_chunks, project_id=None):
def get_chunks(question, vector_name, num_chunks, project_id=None, serving_config=None):
if serving_config is None:
serving_config = "default_serving_config"
de = DiscoveryEngineClient(vector_name, project_id=project_id or get_gcp_project(include_config=True))
try:
return de.get_chunks(question, num_previous_chunks=num_chunks, num_next_chunks=num_chunks)
return de.get_chunks(question, num_previous_chunks=num_chunks, num_next_chunks=num_chunks, serving_config=serving_config)
except Exception as err:
log.error(f"No discovery engine chunks found: {str(err)}")

Expand Down
2 changes: 2 additions & 0 deletions sunholo/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ def load_config_key(key: str, vector_name: str, kind: str):
config = configs_by_kind[kind]

apiVersion = config.get('apiVersion')
if apiVersion is None:
raise ValueError("Could not find apiVersion for config")

log.debug(f"Fetching '{key}' for '{vector_name}' from '{kind}/{apiVersion}'")

Expand Down

0 comments on commit bbec900

Please sign in to comment.