From 877565777a3cda78c55a7ed985d6fb309fa0823b Mon Sep 17 00:00:00 2001 From: Oshoma Momoh Date: Tue, 15 Aug 2023 16:00:00 -0400 Subject: [PATCH] App init: add PINECONE_NAMESPACE environment variable 1. Resolve issue #48 https://github.com/Aggregate-Intellect/practical-llms/issues/48 2. Warn user and exit app if Pinecone API key is set and other Pinecone keys are not set. --- apps/slackbot/.env-sample | 1 + apps/slackbot/bolt_app.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/slackbot/.env-sample b/apps/slackbot/.env-sample index 0f235fa1..5a6f0a56 100644 --- a/apps/slackbot/.env-sample +++ b/apps/slackbot/.env-sample @@ -12,5 +12,6 @@ SLACK_VERIFICATION_TOKEN= # from `Basic Information` page of your Slack # Pinecone. Optional. Enables cloud-based storage of vector embeddings. # PINECONE_API_KEY= # The Pinecone vector database API key +# PINECONE_NAMESPACE="ReadTheDocs" # Pinecone namespace to use for documents # PINECONE_ENV= # Region where the Pinecone index is deployed # PINECONE_INDEX= # The Pinecone vector database index diff --git a/apps/slackbot/bolt_app.py b/apps/slackbot/bolt_app.py index b973de0e..5112cd77 100644 --- a/apps/slackbot/bolt_app.py +++ b/apps/slackbot/bolt_app.py @@ -54,8 +54,15 @@ print("App init: loading documents into Chroma:") local_memory = LocalChromaStore.from_folder('files', OPENAI_KEY).as_retriever() else: - print("App init: Pinecone environment variables are set") - + PINECONE_NAMESPACE = environ.get("PINECONE_NAMESPACE", "ReadTheDocs") + PINECONE_ENV=environ.get("PINECONE_ENV") + PINECONE_INDEX=environ.get("PINECONE_INDEX") + if None in [PINECONE_NAMESPACE, PINECONE_ENV, PINECONE_INDEX]: + print("App init: Pinecone environment variables not set, app is unable to run") + raise SystemExit(1) + else: + print("App init: Pinecone environment variables are set") + print(PINECONE_NAMESPACE) ########################################################################### # Define Slack client functionality: @@ -218,7 +225,7 @@ def get_response(question, previous_messages): if PINECONE_API_KEY: # If pinecone API is specified, then use the Pinecone Database memory = ConversationStore.get_vector_retrieval( - 'ReadTheDocs', OPENAI_KEY, index_name=os.getenv("PINECONE_INDEX"), search_type='similarity_score_threshold', search_kwargs={'score_threshold': 0.0} + PINECONE_NAMESPACE, OPENAI_KEY, index_name=PINECONE_INDEX, search_type='similarity_score_threshold', search_kwargs={'score_threshold': 0.0} ) else: # use the local Chroma database