mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-01 11:02:37 +00:00
docs: update notebook for new Pinecone API + serverless (#21923)
Thank you for contributing to LangChain! - [x] **PR title**: "docs: update notebook for new Pinecone API + serverless" - [x] **PR message**: The published notebook is not runnable after `pinecone-client` v2, which is deprecated. `langchain-pinecone` is not compatible with the latest `pinecone-client` (v4), so I hardcoded it to the last v3. Also updated for serverless indexes (only index type available on Pinecone free plan). - [x] **Add tests and docs**: N/A (tested in Colab) - [x] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/ Additional guidelines: - Make sure optional dependencies are imported within a function. - Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests. - Most PRs should not touch more than one package. - Changes should be backwards compatible. - If you are adding something to community, do not re-import it in langchain. If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, hwchase17. --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1207328087952500
This commit is contained in:
@@ -42,7 +42,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%pip install --upgrade --quiet pinecone-client"
|
"%pip install --upgrade --quiet pinecone-notebooks pinecone-client==3.2.2"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -61,13 +61,50 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
|
"# Connect to Pinecone and get an API key.\n",
|
||||||
|
"from pinecone_notebooks.colab import Authenticate\n",
|
||||||
|
"\n",
|
||||||
|
"Authenticate()\n",
|
||||||
|
"\n",
|
||||||
"import os\n",
|
"import os\n",
|
||||||
"\n",
|
"\n",
|
||||||
"import pinecone\n",
|
"api_key = os.environ[\"PINECONE_API_KEY\"]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "bdaebe0d",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"We want to use `OpenAIEmbeddings` so we have to get the OpenAI API Key."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "04b33384",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import getpass\n",
|
||||||
"\n",
|
"\n",
|
||||||
"pinecone.init(\n",
|
"os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")"
|
||||||
" api_key=os.environ[\"PINECONE_API_KEY\"], environment=os.environ[\"PINECONE_ENV\"]\n",
|
]
|
||||||
")"
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "c9ab3a96",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from pinecone import Pinecone, ServerlessSpec\n",
|
||||||
|
"\n",
|
||||||
|
"api_key = os.getenv(\"PINECONE_API_KEY\") or \"PINECONE_API_KEY\"\n",
|
||||||
|
"\n",
|
||||||
|
"index_name = \"langchain-self-retriever-demo\"\n",
|
||||||
|
"\n",
|
||||||
|
"pc = Pinecone(api_key=api_key)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -82,8 +119,15 @@
|
|||||||
"from langchain_pinecone import PineconeVectorStore\n",
|
"from langchain_pinecone import PineconeVectorStore\n",
|
||||||
"\n",
|
"\n",
|
||||||
"embeddings = OpenAIEmbeddings()\n",
|
"embeddings = OpenAIEmbeddings()\n",
|
||||||
|
"\n",
|
||||||
"# create new index\n",
|
"# create new index\n",
|
||||||
"pinecone.create_index(\"langchain-self-retriever-demo\", dimension=1536)"
|
"if index_name not in pc.list_indexes().names():\n",
|
||||||
|
" pc.create_index(\n",
|
||||||
|
" name=index_name,\n",
|
||||||
|
" dimension=1536,\n",
|
||||||
|
" metric=\"cosine\",\n",
|
||||||
|
" spec=ServerlessSpec(cloud=\"aws\", region=\"us-east-1\"),\n",
|
||||||
|
" )"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user