mirror of
https://github.com/hwchase17/langchain.git
synced 2025-04-27 11:41:51 +00:00
pinecone[patch], docs: PineconeVectorStore, release 0.0.3 (#17896)
This commit is contained in:
parent
e5e38e89ce
commit
a53370a060
@ -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"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -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"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -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",
|
||||
")"
|
||||
]
|
||||
@ -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()"
|
||||
]
|
||||
},
|
||||
|
@ -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)
|
||||
|
@ -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\""
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -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",
|
||||
@ -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",
|
||||
")"
|
||||
]
|
||||
|
@ -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`."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -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!\"])"
|
||||
]
|
||||
|
@ -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"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -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\")"
|
||||
@ -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": {
|
||||
@ -333,4 +324,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
}
|
||||
|
@ -402,7 +402,9 @@ class Pinecone(VectorStore):
|
||||
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.
|
||||
@ -411,21 +413,20 @@ class Pinecone(VectorStore):
|
||||
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)
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
from langchain_pinecone.vectorstores import Pinecone
|
||||
from langchain_pinecone.vectorstores import Pinecone, PineconeVectorStore
|
||||
|
||||
__all__ = [
|
||||
"PineconeVectorStore",
|
||||
"Pinecone",
|
||||
]
|
||||
|
@ -15,6 +15,7 @@ from typing import (
|
||||
)
|
||||
|
||||
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
|
||||
@ -31,13 +32,15 @@ logger = logging.getLogger(__name__)
|
||||
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()
|
||||
@ -401,7 +404,7 @@ class Pinecone(VectorStore):
|
||||
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:
|
||||
@ -411,21 +414,22 @@ class Pinecone(VectorStore):
|
||||
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)
|
||||
@ -450,7 +454,7 @@ class Pinecone(VectorStore):
|
||||
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)
|
||||
@ -485,3 +489,10 @@ class Pinecone(VectorStore):
|
||||
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
|
||||
|
42
libs/partners/pinecone/poetry.lock
generated
42
libs/partners/pinecone/poetry.lock
generated
@ -16,13 +16,13 @@ typing-extensions = {version = ">=4.0.0", markers = "python_version < \"3.9\""}
|
||||
|
||||
[[package]]
|
||||
name = "anyio"
|
||||
version = "4.2.0"
|
||||
version = "4.3.0"
|
||||
description = "High level compatibility layer for multiple asynchronous event loop implementations"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "anyio-4.2.0-py3-none-any.whl", hash = "sha256:745843b39e829e108e518c489b31dc757de7d2131d53fac32bd8df268227bfee"},
|
||||
{file = "anyio-4.2.0.tar.gz", hash = "sha256:e1875bb4b4e2de1669f4bc7869b6d3f54231cdced71605e6e64c9be77e3be50f"},
|
||||
{file = "anyio-4.3.0-py3-none-any.whl", hash = "sha256:048e05d0f6caeed70d731f3db756d35dcc1f35747c8c403364a8332c630441b8"},
|
||||
{file = "anyio-4.3.0.tar.gz", hash = "sha256:f75253795a87df48568485fd18cdd2a3fa5c4f7c5be8e5e36637733fce06fed6"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -226,13 +226,13 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "httpcore"
|
||||
version = "1.0.2"
|
||||
version = "1.0.4"
|
||||
description = "A minimal low-level HTTP client."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "httpcore-1.0.2-py3-none-any.whl", hash = "sha256:096cc05bca73b8e459a1fc3dcf585148f63e534eae4339559c9b8a8d6399acc7"},
|
||||
{file = "httpcore-1.0.2.tar.gz", hash = "sha256:9fc092e4799b26174648e54b74ed5f683132a464e95643b226e00c2ed2fa6535"},
|
||||
{file = "httpcore-1.0.4-py3-none-any.whl", hash = "sha256:ac418c1db41bade2ad53ae2f3834a3a0f5ae76b56cf5aa497d2d033384fc7d73"},
|
||||
{file = "httpcore-1.0.4.tar.gz", hash = "sha256:cb2839ccfcba0d2d3c1131d3c3e26dfc327326fbe7a5dc0dbfe9f6c9151bb022"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -243,17 +243,17 @@ h11 = ">=0.13,<0.15"
|
||||
asyncio = ["anyio (>=4.0,<5.0)"]
|
||||
http2 = ["h2 (>=3,<5)"]
|
||||
socks = ["socksio (==1.*)"]
|
||||
trio = ["trio (>=0.22.0,<0.23.0)"]
|
||||
trio = ["trio (>=0.22.0,<0.25.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "httpx"
|
||||
version = "0.26.0"
|
||||
version = "0.27.0"
|
||||
description = "The next generation HTTP client."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "httpx-0.26.0-py3-none-any.whl", hash = "sha256:8915f5a3627c4d47b73e8202457cb28f1266982d1159bd5779d86a80c0eab1cd"},
|
||||
{file = "httpx-0.26.0.tar.gz", hash = "sha256:451b55c30d5185ea6b23c2c793abf9bb237d2a7dfb901ced6ff69ad37ec1dfaf"},
|
||||
{file = "httpx-0.27.0-py3-none-any.whl", hash = "sha256:71d5465162c13681bff01ad59b2cc68dd838ea1f10e51574bac27103f00c91a5"},
|
||||
{file = "httpx-0.27.0.tar.gz", hash = "sha256:a0cb88a46f32dc874e04ee956e4c2764aba2aa228f650b06788ba6bda2962ab5"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -318,7 +318,7 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "langchain-core"
|
||||
version = "0.1.23"
|
||||
version = "0.1.25"
|
||||
description = "Building applications with LLMs through composability"
|
||||
optional = false
|
||||
python-versions = ">=3.8.1,<4.0"
|
||||
@ -328,7 +328,7 @@ develop = true
|
||||
[package.dependencies]
|
||||
anyio = ">=3,<5"
|
||||
jsonpatch = "^1.33"
|
||||
langsmith = "^0.0.87"
|
||||
langsmith = "^0.1.0"
|
||||
packaging = "^23.2"
|
||||
pydantic = ">=1,<3"
|
||||
PyYAML = ">=5.3"
|
||||
@ -361,13 +361,13 @@ tiktoken = ">=0.5.2,<1"
|
||||
|
||||
[[package]]
|
||||
name = "langsmith"
|
||||
version = "0.0.87"
|
||||
version = "0.1.5"
|
||||
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
|
||||
optional = false
|
||||
python-versions = ">=3.8.1,<4.0"
|
||||
files = [
|
||||
{file = "langsmith-0.0.87-py3-none-any.whl", hash = "sha256:8903d3811b9fc89eb18f5961c8e6935fbd2d0f119884fbf30dc70b8f8f4121fc"},
|
||||
{file = "langsmith-0.0.87.tar.gz", hash = "sha256:36c4cc47e5b54be57d038036a30fb19ce6e4c73048cd7a464b8f25b459694d34"},
|
||||
{file = "langsmith-0.1.5-py3-none-any.whl", hash = "sha256:a1811821a923d90e53bcbacdd0988c3c366aff8f4c120d8777e7af8ecda06268"},
|
||||
{file = "langsmith-0.1.5.tar.gz", hash = "sha256:aa7a2861aa3d9ae563a077c622953533800466c4e2e539b0d567b84d5fd5b157"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -508,13 +508,13 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "pinecone-client"
|
||||
version = "3.0.2"
|
||||
version = "3.0.3"
|
||||
description = "Pinecone client and SDK"
|
||||
optional = false
|
||||
python-versions = ">=3.8,<3.13"
|
||||
files = [
|
||||
{file = "pinecone_client-3.0.2-py3-none-any.whl", hash = "sha256:72696c883b47c0f65808bf623aebe940c07bc396f2126b627aad63d6e3cb6c43"},
|
||||
{file = "pinecone_client-3.0.2.tar.gz", hash = "sha256:f9a0830333eece107b4ef1119de23dad6a61bffab7f238e618416d51c46d29c8"},
|
||||
{file = "pinecone_client-3.0.3-py3-none-any.whl", hash = "sha256:940c942aeb259145e1cd6d3f214ad977dbb4dc2e626b3528fb5015c64c3e6190"},
|
||||
{file = "pinecone_client-3.0.3.tar.gz", hash = "sha256:2ad3ef7627edc4d9ee248d9781861c4341d6d27a15bc05f6bef53d958837d374"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -1092,13 +1092,13 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
version = "2.2.0"
|
||||
version = "2.2.1"
|
||||
description = "HTTP library with thread-safe connection pooling, file post, and more."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "urllib3-2.2.0-py3-none-any.whl", hash = "sha256:ce3711610ddce217e6d113a2732fafad960a03fd0318c91faa79481e35c11224"},
|
||||
{file = "urllib3-2.2.0.tar.gz", hash = "sha256:051d961ad0c62a94e50ecf1af379c3aba230c66c710493493560c0c223c49f20"},
|
||||
{file = "urllib3-2.2.1-py3-none-any.whl", hash = "sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d"},
|
||||
{file = "urllib3-2.2.1.tar.gz", hash = "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
|
@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "langchain-pinecone"
|
||||
version = "0.0.2"
|
||||
version = "0.0.3"
|
||||
description = "An integration package connecting Pinecone and LangChain"
|
||||
authors = []
|
||||
readme = "README.md"
|
||||
|
@ -10,7 +10,7 @@ from langchain_core.documents import Document
|
||||
from langchain_openai import OpenAIEmbeddings
|
||||
from pinecone import PodSpec
|
||||
|
||||
from langchain_pinecone import Pinecone
|
||||
from langchain_pinecone import PineconeVectorStore
|
||||
|
||||
INDEX_NAME = "langchain-test-index" # name of the index
|
||||
NAMESPACE_NAME = "langchain-test-namespace" # name of the namespace
|
||||
@ -80,7 +80,7 @@ class TestPinecone:
|
||||
needs = f"foobuu {unique_id} booo"
|
||||
texts.insert(0, needs)
|
||||
|
||||
docsearch = Pinecone.from_texts(
|
||||
docsearch = PineconeVectorStore.from_texts(
|
||||
texts=texts,
|
||||
embedding=embedding_openai,
|
||||
index_name=INDEX_NAME,
|
||||
@ -102,7 +102,7 @@ class TestPinecone:
|
||||
metadatas = [{"page": i} for i in range(len(texts))]
|
||||
|
||||
namespace = f"{NAMESPACE_NAME}-md"
|
||||
docsearch = Pinecone.from_texts(
|
||||
docsearch = PineconeVectorStore.from_texts(
|
||||
texts,
|
||||
embedding_openai,
|
||||
index_name=INDEX_NAME,
|
||||
@ -120,7 +120,7 @@ class TestPinecone:
|
||||
texts = ["foo", "bar", "baz"]
|
||||
metadatas = [{"page": i} for i in range(len(texts))]
|
||||
print("metadatas", metadatas) # noqa: T201
|
||||
docsearch = Pinecone.from_texts(
|
||||
docsearch = PineconeVectorStore.from_texts(
|
||||
texts,
|
||||
embedding_openai,
|
||||
index_name=INDEX_NAME,
|
||||
@ -152,7 +152,7 @@ class TestPinecone:
|
||||
# Create two indexes with the same name but different namespaces
|
||||
texts_1 = ["foo", "bar", "baz"]
|
||||
metadatas = [{"page": i} for i in range(len(texts_1))]
|
||||
Pinecone.from_texts(
|
||||
PineconeVectorStore.from_texts(
|
||||
texts_1,
|
||||
embedding_openai,
|
||||
index_name=INDEX_NAME,
|
||||
@ -163,7 +163,7 @@ class TestPinecone:
|
||||
texts_2 = ["foo2", "bar2", "baz2"]
|
||||
metadatas = [{"page": i} for i in range(len(texts_2))]
|
||||
|
||||
Pinecone.from_texts(
|
||||
PineconeVectorStore.from_texts(
|
||||
texts_2,
|
||||
embedding_openai,
|
||||
index_name=INDEX_NAME,
|
||||
@ -174,7 +174,7 @@ class TestPinecone:
|
||||
time.sleep(DEFAULT_SLEEP) # prevent race condition
|
||||
|
||||
# Search with namespace
|
||||
docsearch = Pinecone.from_existing_index(
|
||||
docsearch = PineconeVectorStore.from_existing_index(
|
||||
index_name=INDEX_NAME,
|
||||
embedding=embedding_openai,
|
||||
namespace=f"{INDEX_NAME}-1",
|
||||
@ -189,7 +189,7 @@ class TestPinecone:
|
||||
self, texts: List[str], embedding_openai: OpenAIEmbeddings
|
||||
) -> None:
|
||||
ids = [uuid.uuid4().hex for _ in range(len(texts))]
|
||||
Pinecone.from_texts(
|
||||
PineconeVectorStore.from_texts(
|
||||
texts=texts,
|
||||
ids=ids,
|
||||
embedding=embedding_openai,
|
||||
@ -201,7 +201,7 @@ class TestPinecone:
|
||||
assert index_stats["namespaces"][NAMESPACE_NAME]["vector_count"] == len(texts)
|
||||
|
||||
ids_1 = [uuid.uuid4().hex for _ in range(len(texts))]
|
||||
Pinecone.from_texts(
|
||||
PineconeVectorStore.from_texts(
|
||||
texts=[t + "-1" for t in texts],
|
||||
ids=ids_1,
|
||||
embedding=embedding_openai,
|
||||
@ -221,7 +221,7 @@ class TestPinecone:
|
||||
"""Ensures all relevance scores are between 0 and 1."""
|
||||
texts = ["foo", "bar", "baz"]
|
||||
metadatas = [{"page": i} for i in range(len(texts))]
|
||||
docsearch = Pinecone.from_texts(
|
||||
docsearch = PineconeVectorStore.from_texts(
|
||||
texts,
|
||||
embedding_openai,
|
||||
index_name=INDEX_NAME,
|
||||
@ -274,7 +274,7 @@ class TestPinecone:
|
||||
texts = [document.page_content for document in documents] * data_multiplier
|
||||
uuids = [uuid.uuid4().hex for _ in range(len(texts))]
|
||||
metadatas = [{"page": i} for i in range(len(texts))]
|
||||
docsearch = Pinecone.from_texts(
|
||||
docsearch = PineconeVectorStore.from_texts(
|
||||
texts,
|
||||
embedding_openai,
|
||||
ids=uuids,
|
||||
|
@ -1,6 +1,7 @@
|
||||
from langchain_pinecone import __all__
|
||||
|
||||
EXPECTED_ALL = [
|
||||
"PineconeVectorStore",
|
||||
"Pinecone",
|
||||
]
|
||||
|
||||
|
@ -6,7 +6,7 @@ Highlighting a few different categories of templates
|
||||
|
||||
These are some of the more popular templates to get started with.
|
||||
|
||||
- [Retrieval Augmented Generation Chatbot](../rag-conversation): Build a chatbot over your data. Defaults to OpenAI and Pinecone.
|
||||
- [Retrieval Augmented Generation Chatbot](../rag-conversation): Build a chatbot over your data. Defaults to OpenAI and PineconeVectorStore.
|
||||
- [Extraction with OpenAI Functions](../extraction-openai-functions): Do extraction of structured data from unstructured data. Uses OpenAI function calling.
|
||||
- [Local Retrieval Augmented Generation](../rag-chroma-private): Build a chatbot over your data. Uses only local tooling: Ollama, GPT4all, Chroma.
|
||||
- [OpenAI Functions Agent](../openai-functions-agent): Build a chatbot that can take actions. Uses OpenAI function calling and Tavily.
|
||||
|
@ -5,7 +5,6 @@ from typing import List, Tuple
|
||||
from langchain.schema import AIMessage, HumanMessage, format_document
|
||||
from langchain_community.chat_models import ChatOpenAI
|
||||
from langchain_community.embeddings import OpenAIEmbeddings
|
||||
from langchain_community.vectorstores import Pinecone
|
||||
from langchain_core.output_parsers import StrOutputParser
|
||||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
from langchain_core.prompts.prompt import PromptTemplate
|
||||
@ -16,6 +15,7 @@ from langchain_core.runnables import (
|
||||
RunnableParallel,
|
||||
RunnablePassthrough,
|
||||
)
|
||||
from langchain_pinecone import PineconeVectorStore
|
||||
|
||||
if os.environ.get("PINECONE_API_KEY", None) is None:
|
||||
raise Exception("Missing `PINECONE_API_KEY` environment variable.")
|
||||
@ -37,12 +37,14 @@ PINECONE_INDEX_NAME = os.environ.get("PINECONE_INDEX", "langchain-test")
|
||||
# all_splits = text_splitter.split_documents(data)
|
||||
|
||||
# # Add to vectorDB
|
||||
# vectorstore = Pinecone.from_documents(
|
||||
# vectorstore = PineconeVectorStore.from_documents(
|
||||
# documents=all_splits, embedding=OpenAIEmbeddings(), index_name=PINECONE_INDEX_NAME
|
||||
# )
|
||||
# retriever = vectorstore.as_retriever()
|
||||
|
||||
vectorstore = Pinecone.from_existing_index(PINECONE_INDEX_NAME, OpenAIEmbeddings())
|
||||
vectorstore = PineconeVectorStore.from_existing_index(
|
||||
PINECONE_INDEX_NAME, OpenAIEmbeddings()
|
||||
)
|
||||
retriever = vectorstore.as_retriever()
|
||||
|
||||
# Condense a chat history and follow-up question into a standalone question
|
||||
|
@ -1,5 +1,5 @@
|
||||
from langchain_community.embeddings import OpenAIEmbeddings
|
||||
from langchain_community.vectorstores import Pinecone
|
||||
from langchain_pinecone import PineconeVectorStore
|
||||
|
||||
all_documents = {
|
||||
"doc1": "Climate change and economic impact.",
|
||||
@ -14,6 +14,6 @@ all_documents = {
|
||||
"doc10": "The history of climate change activism.",
|
||||
}
|
||||
|
||||
Pinecone.from_texts(
|
||||
PineconeVectorStore.from_texts(
|
||||
list(all_documents.values()), OpenAIEmbeddings(), index_name="rag-fusion"
|
||||
)
|
||||
|
@ -2,9 +2,9 @@ from langchain import hub
|
||||
from langchain.load import dumps, loads
|
||||
from langchain_community.chat_models import ChatOpenAI
|
||||
from langchain_community.embeddings import OpenAIEmbeddings
|
||||
from langchain_community.vectorstores import Pinecone
|
||||
from langchain_core.output_parsers import StrOutputParser
|
||||
from langchain_core.pydantic_v1 import BaseModel
|
||||
from langchain_pinecone import PineconeVectorStore
|
||||
|
||||
|
||||
def reciprocal_rank_fusion(results: list[list], k=60):
|
||||
@ -30,7 +30,7 @@ generate_queries = (
|
||||
prompt | ChatOpenAI(temperature=0) | StrOutputParser() | (lambda x: x.split("\n"))
|
||||
)
|
||||
|
||||
vectorstore = Pinecone.from_existing_index("rag-fusion", OpenAIEmbeddings())
|
||||
vectorstore = PineconeVectorStore.from_existing_index("rag-fusion", OpenAIEmbeddings())
|
||||
retriever = vectorstore.as_retriever()
|
||||
|
||||
chain = (
|
||||
|
@ -3,11 +3,11 @@ import os
|
||||
from langchain.retrievers.multi_query import MultiQueryRetriever
|
||||
from langchain_community.chat_models import ChatOpenAI
|
||||
from langchain_community.embeddings import OpenAIEmbeddings
|
||||
from langchain_community.vectorstores import Pinecone
|
||||
from langchain_core.output_parsers import StrOutputParser
|
||||
from langchain_core.prompts import ChatPromptTemplate
|
||||
from langchain_core.pydantic_v1 import BaseModel
|
||||
from langchain_core.runnables import RunnableParallel, RunnablePassthrough
|
||||
from langchain_pinecone import PineconeVectorStore
|
||||
|
||||
if os.environ.get("PINECONE_API_KEY", None) is None:
|
||||
raise Exception("Missing `PINECONE_API_KEY` environment variable.")
|
||||
@ -29,13 +29,15 @@ PINECONE_INDEX_NAME = os.environ.get("PINECONE_INDEX", "langchain-test")
|
||||
# all_splits = text_splitter.split_documents(data)
|
||||
|
||||
# # Add to vectorDB
|
||||
# vectorstore = Pinecone.from_documents(
|
||||
# vectorstore = PineconeVectorStore.from_documents(
|
||||
# documents=all_splits, embedding=OpenAIEmbeddings(), index_name=PINECONE_INDEX_NAME
|
||||
# )
|
||||
# retriever = vectorstore.as_retriever()
|
||||
|
||||
# Set up index with multi query retriever
|
||||
vectorstore = Pinecone.from_existing_index(PINECONE_INDEX_NAME, OpenAIEmbeddings())
|
||||
vectorstore = PineconeVectorStore.from_existing_index(
|
||||
PINECONE_INDEX_NAME, OpenAIEmbeddings()
|
||||
)
|
||||
model = ChatOpenAI(temperature=0)
|
||||
retriever = MultiQueryRetriever.from_llm(
|
||||
retriever=vectorstore.as_retriever(), llm=model
|
||||
|
@ -4,11 +4,11 @@ from langchain.retrievers import ContextualCompressionRetriever
|
||||
from langchain.retrievers.document_compressors import CohereRerank
|
||||
from langchain_community.chat_models import ChatOpenAI
|
||||
from langchain_community.embeddings import OpenAIEmbeddings
|
||||
from langchain_community.vectorstores import Pinecone
|
||||
from langchain_core.output_parsers import StrOutputParser
|
||||
from langchain_core.prompts import ChatPromptTemplate
|
||||
from langchain_core.pydantic_v1 import BaseModel
|
||||
from langchain_core.runnables import RunnableParallel, RunnablePassthrough
|
||||
from langchain_pinecone import PineconeVectorStore
|
||||
|
||||
if os.environ.get("PINECONE_API_KEY", None) is None:
|
||||
raise Exception("Missing `PINECONE_API_KEY` environment variable.")
|
||||
@ -30,12 +30,14 @@ PINECONE_INDEX_NAME = os.environ.get("PINECONE_INDEX", "langchain-test")
|
||||
# all_splits = text_splitter.split_documents(data)
|
||||
|
||||
# # Add to vectorDB
|
||||
# vectorstore = Pinecone.from_documents(
|
||||
# vectorstore = PineconeVectorStore.from_documents(
|
||||
# documents=all_splits, embedding=OpenAIEmbeddings(), index_name=PINECONE_INDEX_NAME
|
||||
# )
|
||||
# retriever = vectorstore.as_retriever()
|
||||
|
||||
vectorstore = Pinecone.from_existing_index(PINECONE_INDEX_NAME, OpenAIEmbeddings())
|
||||
vectorstore = PineconeVectorStore.from_existing_index(
|
||||
PINECONE_INDEX_NAME, OpenAIEmbeddings()
|
||||
)
|
||||
|
||||
# Get k=10 docs
|
||||
retriever = vectorstore.as_retriever(search_kwargs={"k": 10})
|
||||
|
@ -2,11 +2,11 @@ import os
|
||||
|
||||
from langchain_community.chat_models import ChatOpenAI
|
||||
from langchain_community.embeddings import OpenAIEmbeddings
|
||||
from langchain_community.vectorstores import Pinecone
|
||||
from langchain_core.output_parsers import StrOutputParser
|
||||
from langchain_core.prompts import ChatPromptTemplate
|
||||
from langchain_core.pydantic_v1 import BaseModel
|
||||
from langchain_core.runnables import RunnableParallel, RunnablePassthrough
|
||||
from langchain_pinecone import PineconeVectorStore
|
||||
|
||||
if os.environ.get("PINECONE_API_KEY", None) is None:
|
||||
raise Exception("Missing `PINECONE_API_KEY` environment variable.")
|
||||
@ -28,12 +28,14 @@ PINECONE_INDEX_NAME = os.environ.get("PINECONE_INDEX", "langchain-test")
|
||||
# all_splits = text_splitter.split_documents(data)
|
||||
|
||||
# # Add to vectorDB
|
||||
# vectorstore = Pinecone.from_documents(
|
||||
# vectorstore = PineconeVectorStore.from_documents(
|
||||
# documents=all_splits, embedding=OpenAIEmbeddings(), index_name=PINECONE_INDEX_NAME
|
||||
# )
|
||||
# retriever = vectorstore.as_retriever()
|
||||
|
||||
vectorstore = Pinecone.from_existing_index(PINECONE_INDEX_NAME, OpenAIEmbeddings())
|
||||
vectorstore = PineconeVectorStore.from_existing_index(
|
||||
PINECONE_INDEX_NAME, OpenAIEmbeddings()
|
||||
)
|
||||
retriever = vectorstore.as_retriever()
|
||||
|
||||
# RAG prompt
|
||||
|
Loading…
Reference in New Issue
Block a user