Skip to content

Commit

Permalink
App init: add PINECONE_NAMESPACE environment variable
Browse files Browse the repository at this point in the history
1. Resolve issue #48
#48

2. Warn user and exit app if Pinecone API key is set and other Pinecone
keys are not set.
  • Loading branch information
oshoma committed Aug 16, 2023
1 parent 6c05f11 commit 8775657
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/slackbot/.env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 10 additions & 3 deletions apps/slackbot/bolt_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8775657

Please sign in to comment.