mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-28 17:38:36 +00:00
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:
parent
8ee56b9a5b
commit
3892cefac6
@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"!pip install pinecone-client openai tiktoken"
|
"!pip install pinecone-client openai tiktoken langchain"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -38,7 +38,7 @@
|
|||||||
"import os\n",
|
"import os\n",
|
||||||
"import getpass\n",
|
"import getpass\n",
|
||||||
"\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": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"PINECONE_ENV = getpass.getpass(\"Pinecone Environment:\")"
|
"os.environ[\"PINECONE_ENV\"] = getpass.getpass(\"Pinecone Environment:\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -113,12 +113,22 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"# initialize pinecone\n",
|
"# initialize pinecone\n",
|
||||||
"pinecone.init(\n",
|
"pinecone.init(\n",
|
||||||
" api_key=PINECONE_API_KEY, # find at app.pinecone.io\n",
|
" api_key=os.getenv(\"PINECONE_API_KEY\"), # find at app.pinecone.io\n",
|
||||||
" environment=PINECONE_ENV, # next to api key in console\n",
|
" environment=os.getenv(\"PINECONE_ENV\"), # next to api key in console\n",
|
||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"index_name = \"langchain-demo\"\n",
|
"index_name = \"langchain-demo\"\n",
|
||||||
"\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",
|
"docsearch = Pinecone.from_documents(docs, embeddings, index_name=index_name)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# if you already have an index, you can load it like this\n",
|
"# if you already have an index, you can load it like this\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user