Skip to content

Commit

Permalink
pinecone[patch], docs: PineconeVectorStore, release 0.0.3 (#17896)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored Feb 22, 2024
1 parent e5e38e8 commit a53370a
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 128 deletions.
13 changes: 6 additions & 7 deletions cookbook/rag_fusion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"source": [
"## Setup\n",
"\n",
"For this example, we will use Pinecone and some fake data"
"For this example, we will use Pinecone and some fake data. To configure Pinecone, set the following environment variable:\n",
"\n",
"- `PINECONE_API_KEY`: Your Pinecone API key"
]
},
{
Expand All @@ -29,11 +31,8 @@
"metadata": {},
"outputs": [],
"source": [
"import pinecone\n",
"from langchain_community.vectorstores import Pinecone\n",
"from langchain_openai import OpenAIEmbeddings\n",
"\n",
"pinecone.init(api_key=\"...\", environment=\"...\")"
"from langchain_pinecone import PineconeVectorStore"
]
},
{
Expand Down Expand Up @@ -64,7 +63,7 @@
"metadata": {},
"outputs": [],
"source": [
"vectorstore = Pinecone.from_texts(\n",
"vectorstore = PineconeVectorStore.from_texts(\n",
" list(all_documents.values()), OpenAIEmbeddings(), index_name=\"rag-fusion\"\n",
")"
]
Expand Down Expand Up @@ -162,7 +161,7 @@
"metadata": {},
"outputs": [],
"source": [
"vectorstore = Pinecone.from_existing_index(\"rag-fusion\", OpenAIEmbeddings())\n",
"vectorstore = PineconeVectorStore.from_existing_index(\"rag-fusion\", OpenAIEmbeddings())\n",
"retriever = vectorstore.as_retriever()"
]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/providers/pinecone.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ There exists a wrapper around Pinecone indexes, allowing you to use it as a vect
whether for semantic search or example selection.

```python
from langchain_community.vectorstores import Pinecone
from langchain_pinecone import PineconeVectorStore
```

For a more detailed walkthrough of the Pinecone vectorstore, see [this notebook](/docs/integrations/vectorstores/pinecone)
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,8 @@
"import pinecone\n",
"\n",
"api_key = os.getenv(\"PINECONE_API_KEY\") or \"PINECONE_API_KEY\"\n",
"# find environment next to your API key in the Pinecone console\n",
"env = os.getenv(\"PINECONE_ENVIRONMENT\") or \"PINECONE_ENVIRONMENT\"\n",
"\n",
"index_name = \"langchain-pinecone-hybrid-search\"\n",
"\n",
"pinecone.init(api_key=api_key, environment=env)\n",
"pinecone.whoami()"
"index_name = \"langchain-pinecone-hybrid-search\""
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/retrievers/self_query/pinecone.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"outputs": [],
"source": [
"from langchain.schema import Document\n",
"from langchain_community.vectorstores import Pinecone\n",
"from langchain_openai import OpenAIEmbeddings\n",
"from langchain_pinecone import PineconeVectorStore\n",
"\n",
"embeddings = OpenAIEmbeddings()\n",
"# create new index\n",
Expand Down Expand Up @@ -124,7 +124,7 @@
" },\n",
" ),\n",
"]\n",
"vectorstore = Pinecone.from_documents(\n",
"vectorstore = PineconeVectorStore.from_documents(\n",
" docs, embeddings, index_name=\"langchain-self-retriever-demo\"\n",
")"
]
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/integrations/vectorstores/pinecone.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"source": [
"Now let's assume you have your Pinecone index set up with `dimension=1536`.\n",
"\n",
"We can connect to our Pinecone index and insert those chunked docs as contents with `Pinecone.from_documents`."
"We can connect to our Pinecone index and insert those chunked docs as contents with `PineconeVectorStore.from_documents`."
]
},
{
Expand All @@ -81,11 +81,11 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain_pinecone import Pinecone\n",
"from langchain_pinecone import PineconeVectorStore\n",
"\n",
"index_name = \"langchain-test-index\"\n",
"\n",
"docsearch = Pinecone.from_documents(docs, embeddings, index_name=index_name)"
"docsearch = PineconeVectorStore.from_documents(docs, embeddings, index_name=index_name)"
]
},
{
Expand Down Expand Up @@ -143,7 +143,7 @@
}
],
"source": [
"vectorstore = Pinecone(index_name=index_name, embedding=embeddings)\n",
"vectorstore = PineconeVectorStore(index_name=index_name, embedding=embeddings)\n",
"\n",
"vectorstore.add_texts([\"More text!\"])"
]
Expand Down
41 changes: 16 additions & 25 deletions docs/docs/use_cases/question_answering/per_user.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,22 @@
"\n",
"## Code Example\n",
"\n",
"Let's see a concrete example of what this looks like in code. We will use Pinecone for this example."
"Let's see a concrete example of what this looks like in code. We will use Pinecone for this example.\n",
"\n",
"To configure Pinecone, set the following environment variable:\n",
"\n",
"- `PINECONE_API_KEY`: Your Pinecone API key"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "75823b2d",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/harrisonchase/.pyenv/versions/3.10.1/envs/langchain/lib/python3.10/site-packages/pinecone/index.py:4: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n",
" from tqdm.autonotebook import tqdm\n"
]
}
],
"outputs": [],
"source": [
"import pinecone\n",
"from langchain_community.vectorstores import Pinecone\n",
"from langchain_openai import OpenAIEmbeddings"
"from langchain_openai import OpenAIEmbeddings\n",
"from langchain_pinecone import PineconeVectorStore"
]
},
{
Expand All @@ -77,12 +71,8 @@
}
],
"source": [
"# The environment should be the one specified next to the API key\n",
"# in your Pinecone console\n",
"pinecone.init(api_key=\"...\", environment=\"...\")\n",
"index = pinecone.Index(\"test-example\")\n",
"embeddings = OpenAIEmbeddings()\n",
"vectorstore = Pinecone(index, embeddings, \"text\")\n",
"vectorstore = PineconeVectorStore(index_name=\"test-example\", embedding=embeddings)\n",
"\n",
"vectorstore.add_texts([\"i worked at kensho\"], namespace=\"harrison\")\n",
"vectorstore.add_texts([\"i worked at facebook\"], namespace=\"ankush\")"
Expand Down Expand Up @@ -301,15 +291,16 @@
},
{
"cell_type": "markdown",
"source": [
"For more vectorstore implementations for multi-user, please refer to specific pages, such as [Milvus](/docs/integrations/vectorstores/milvus)."
],
"id": "7fb27b941602401d91542211134fc71a",
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
"source": [
"For more vectorstore implementations for multi-user, please refer to specific pages, such as [Milvus](/docs/integrations/vectorstores/milvus)."
]
}
],
"metadata": {
Expand All @@ -333,4 +324,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
23 changes: 12 additions & 11 deletions libs/community/langchain_community/vectorstores/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ def from_texts(
embeddings_chunk_size: int = 1000,
**kwargs: Any,
) -> Pinecone:
"""Construct Pinecone wrapper from raw documents.
"""
DEPRECATED: use langchain_pinecone.PineconeVectorStore.from_texts instead:
Construct Pinecone wrapper from raw documents.
This is a user friendly interface that:
1. Embeds documents.
Expand All @@ -411,21 +413,20 @@ def from_texts(
This is intended to be a quick way to get started.
The `pool_threads` affects the speed of the upsert operations.
Example:
.. code-block:: python
from langchain_community.vectorstores import Pinecone
from langchain_community.embeddings import OpenAIEmbeddings
import pinecone
from langchain_pinecone import PineconeVectorStore
from langchain_openai import OpenAIEmbeddings
# The environment should be the one specified next to the API key
# in your Pinecone console
pinecone.init(api_key="***", environment="...")
embeddings = OpenAIEmbeddings()
pinecone = Pinecone.from_texts(
texts,
embeddings,
index_name="langchain-demo"
index_name = "my-index"
namespace = "my-namespace"
vectorstore = Pinecone(
index_name=index_name,
embedding=embedding,
namespace=namespace,
)
"""
pinecone_index = cls.get_pinecone_index(index_name, pool_threads)
Expand Down
8 changes: 2 additions & 6 deletions libs/partners/pinecone/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ all: help

# Define a variable for the test file path.
TEST_FILE ?= tests/unit_tests/
integration_test integration_tests: TEST_FILE = tests/integration_tests/

integration_tests: TEST_FILE = tests/integration_tests/

test integration_tests:
poetry run pytest $(TEST_FILE)

tests:
test tests integration_test integration_tests:
poetry run pytest $(TEST_FILE)


Expand Down
3 changes: 1 addition & 2 deletions libs/partners/pinecone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ And you should configure credentials by setting the following environment variab

- `PINECONE_API_KEY`
- `PINECONE_INDEX_NAME`
- `PINECONE_ENVIRONMENT`

## Usage

The `Pinecone` class exposes the connection to the Pinecone vector store.

```python
from langchain_pinecone import Pinecone
from langchain_pinecone import PineconeVectorStore

embeddings = ... # use a LangChain Embeddings class

Expand Down
3 changes: 2 additions & 1 deletion libs/partners/pinecone/langchain_pinecone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from langchain_pinecone.vectorstores import Pinecone
from langchain_pinecone.vectorstores import Pinecone, PineconeVectorStore

__all__ = [
"PineconeVectorStore",
"Pinecone",
]
37 changes: 24 additions & 13 deletions libs/partners/pinecone/langchain_pinecone/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)

import numpy as np
from langchain_core._api.deprecation import deprecated
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_core.utils.iter import batch_iterate
Expand All @@ -31,13 +32,15 @@
VST = TypeVar("VST", bound=VectorStore)


class Pinecone(VectorStore):
class PineconeVectorStore(VectorStore):
"""`Pinecone` vector store.
Setup: set the `PINECONE_API_KEY` environment variable to your Pinecone API key.
Example:
.. code-block:: python
from langchain_pinecone import Pinecone
from langchain_pinecone import PineconeVectorStore
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
Expand Down Expand Up @@ -401,7 +404,7 @@ def from_texts(
pool_threads: int = 4,
embeddings_chunk_size: int = 1000,
**kwargs: Any,
) -> Pinecone:
) -> PineconeVectorStore:
"""Construct Pinecone wrapper from raw documents.
This is a user friendly interface that:
Expand All @@ -411,21 +414,22 @@ def from_texts(
This is intended to be a quick way to get started.
The `pool_threads` affects the speed of the upsert operations.
Setup: set the `PINECONE_API_KEY` environment variable to your Pinecone API key.
Example:
.. code-block:: python
from langchain_community.vectorstores import Pinecone
from langchain_community.embeddings import OpenAIEmbeddings
import pinecone
from langchain_pinecone import PineconeVectorStore
from langchain_openai import OpenAIEmbeddings
# The environment should be the one specified next to the API key
# in your Pinecone console
pinecone.init(api_key="***", environment="...")
embeddings = OpenAIEmbeddings()
pinecone = Pinecone.from_texts(
index_name = "my-index"
vectorstore = PineconeVectorStore.from_texts(
texts,
embeddings,
index_name="langchain-demo"
index_name=index_name,
embedding=embedding,
namespace=namespace,
)
"""
pinecone_index = cls.get_pinecone_index(index_name, pool_threads)
Expand All @@ -450,7 +454,7 @@ def from_existing_index(
text_key: str = "text",
namespace: Optional[str] = None,
pool_threads: int = 4,
) -> Pinecone:
) -> PineconeVectorStore:
"""Load pinecone vectorstore from index name."""
pinecone_index = cls.get_pinecone_index(index_name, pool_threads)
return cls(pinecone_index, embedding, text_key, namespace)
Expand Down Expand Up @@ -485,3 +489,10 @@ def delete(
raise ValueError("Either ids, delete_all, or filter must be provided.")

return None


@deprecated(since="0.0.3", removal="0.2.0", alternative="PineconeVectorStore")
class Pinecone(PineconeVectorStore):
"""Deprecated. Use PineconeVectorStore instead."""

pass
Loading

0 comments on commit a53370a

Please sign in to comment.