Skip to content

The agent engineering platform.

docs: Update Pinecone example notebook with embedded widget (#21719)

junefishc5a981e3b4f0
diff --git a/docs/docs/integrations/vectorstores/pinecone.ipynb b/docs/docs/integrations/vectorstores/pinecone.ipynb
index 4e4a479843..c305b5053d 100644
--- a/docs/docs/integrations/vectorstores/pinecone.ipynb
+++ b/docs/docs/integrations/vectorstores/pinecone.ipynb
@@ -12,16 +12,7 @@
"\n",
"This notebook shows how to use functionality related to the `Pinecone` vector database.\n",
"\n",
- "To use Pinecone, you must have an API key. \n",
- "Here are the [installation instructions](https://docs.pinecone.io/docs/quickstart).\n",
- "\n",
- "Set the following environment variables to make using the `Pinecone` integration easier:\n",
- "\n",
- "- `PINECONE_API_KEY`: Your Pinecone API key.\n",
- "- `PINECONE_INDEX_NAME`: The name of the index you want to use.\n",
- "\n",
- "And to follow along in this doc, you should also set\n",
- "\n",
+ "Set the following environment variables to follow along in this doc:\n",
"- `OPENAI_API_KEY`: Your OpenAI API key, for using `OpenAIEmbeddings`"
]
},
@@ -34,7 +25,11 @@
},
"outputs": [],
"source": [
- "%pip install --upgrade --quiet langchain-pinecone langchain-openai langchain"
+ "%pip install --upgrade --quiet \\\n",
+ " langchain-pinecone \\\n",
+ " langchain-openai \\\n",
+ " langchain \\\n",
+ " pinecone-notebooks"
]
},
{
@@ -74,12 +69,91 @@
},
{
"cell_type": "markdown",
- "id": "3a4d377f",
+ "id": "ef6dc4de",
+ "metadata": {},
+ "source": [
+ "Now let's create a new Pinecone account, or sign into your existing one, and create an API key to use in this notebook."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "1fdc3c36",
"metadata": {},
+ "outputs": [],
"source": [
- "Now let's assume you have your Pinecone index set up with `dimension=1536`.\n",
+ "from pinecone_notebooks.colab import Authenticate\n",
"\n",
- "We can connect to our Pinecone index and insert those chunked docs as contents with `PineconeVectorStore.from_documents`."
+ "Authenticate()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "54da1a39",
+ "metadata": {},
+ "source": [
+ "The newly created API key has been stored in the `PINECONE_API_KEY` environment variable. We will use it to setup the Pinecone client."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "eb554814",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "\n",
+ "pinecone_api_key = os.environ.get(\"PINECONE_API_KEY\")\n",
+ "pinecone_api_key\n",
+ "\n",
+ "import time\n",
+ "\n",
+ "from pinecone import Pinecone, ServerlessSpec\n",
+ "\n",
+ "pc = Pinecone(api_key=pinecone_api_key)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "658706a3",
+ "metadata": {},
+ "source": [
+ "Next, let's connect to your Pinecone index. If one named `index_name` doesn't exist, it will be created."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "276a06dd",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import time\n",
+ "\n",
+ "index_name = \"langchain-index\" # change if desired\n",
+ "\n",
+ "existing_indexes = [index_info[\"name\"] for index_info in pc.list_indexes()]\n",
+ "\n",
+ "if index_name not in existing_indexes:\n",
+ " pc.create_index(\n",
+ " name=index_name,\n",
+ " dimension=1536,\n",
+ " metric=\"cosine\",\n",
+ " spec=ServerlessSpec(cloud=\"aws\", region=\"us-east-1\"),\n",
+ " )\n",
+ " while not pc.describe_index(index_name).status[\"ready\"]:\n",
+ " time.sleep(1)\n",
+ "\n",
+ "index = pc.Index(index_name)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "3a4d377f",
+ "metadata": {},
+ "source": [
+ "Now that our Pinecone index is setup, we can upsert those chunked docs as contents with `PineconeVectorStore.from_documents`."
]
},
{
@@ -91,8 +165,6 @@
"source": [
"from langchain_pinecone import PineconeVectorStore\n",
"\n",
- "index_name = \"langchain-test-index\"\n",
- "\n",
"docsearch = PineconeVectorStore.from_documents(docs, embeddings, index_name=index_name)"
]
},
@@ -315,14 +387,6 @@
"for i, doc in enumerate(found_docs):\n",
" print(f\"{i + 1}.\", doc.page_content, \"\\n\")"
]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "b0fd750b",
- "metadata": {},
- "outputs": [],
- "source": []
}
],
"metadata": {
@@ -341,7 +405,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.11.4"
+ "version": "3.11.6"
}
},
"nbformat": 4,