Minor fixes to enhance notebook usability: (#8389)

- Install langchain
- Set Pinecone API key and environment as env vars
- Create Pinecone index if it doesn't already exist
---
- Description: Fix a couple minor issues I came across when running this
notebook,
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: none,
  - Tag maintainer: @rlancemartin @eyurtsev,
  - Twitter handle: @zackproser (certainly not necessary!)
This commit is contained in:
Zack Proser 2023-07-28 20:10:03 -04:00 committed by GitHub
parent 8ee56b9a5b
commit 3892cefac6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,7 +25,7 @@
},
"outputs": [],
"source": [
"!pip install pinecone-client openai tiktoken"
"!pip install pinecone-client openai tiktoken langchain"
]
},
{
@ -38,7 +38,7 @@
"import os\n",
"import getpass\n",
"\n",
"PINECONE_API_KEY = getpass.getpass(\"Pinecone API Key:\")"
"os.environ[\"PINECONE_API_KEY\"] = getpass.getpass(\"Pinecone API Key:\")"
]
},
{
@ -48,7 +48,7 @@
"metadata": {},
"outputs": [],
"source": [
"PINECONE_ENV = getpass.getpass(\"Pinecone Environment:\")"
"os.environ[\"PINECONE_ENV\"] = getpass.getpass(\"Pinecone Environment:\")"
]
},
{
@ -113,12 +113,22 @@
"\n",
"# initialize pinecone\n",
"pinecone.init(\n",
" api_key=PINECONE_API_KEY, # find at app.pinecone.io\n",
" environment=PINECONE_ENV, # next to api key in console\n",
" api_key=os.getenv(\"PINECONE_API_KEY\"), # find at app.pinecone.io\n",
" environment=os.getenv(\"PINECONE_ENV\"), # next to api key in console\n",
")\n",
"\n",
"index_name = \"langchain-demo\"\n",
"\n",
"# First, check if our index already exists. If it doesn't, we create it\n",
"if index_name not in pinecone.list_indexes():\n",
" # we create a new index\n",
" pinecone.create_index(\n",
" name=index_name,\n",
" metric='cosine',\n",
" dimension=1536 \n",
")\n",
"# The OpenAI embedding model `text-embedding-ada-002 uses 1536 dimensions`\n",
"docsearch = Pinecone.from_documents(docs, embeddings, index_name=index_name)\n",
"\n",
"# if you already have an index, you can load it like this\n",