Install & Compatibility
Where this runs
tested against v0.2.13 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 2.760s · 190.3MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 16.1s · import 2.570s · 196MB
198MB installed
● package 198MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
PineconeVectorStore
✓ from langchain_pinecone import PineconeVectorStore
OpenAIEmbeddings
✓ from langchain_openai import OpenAIEmbeddings
✗ from langchain.embeddings import OpenAIEmbeddings
OpenAI embeddings were moved to the `langchain-openai` package in LangChain v0.1.x.
Pinecone
✓ from pinecone import Pinecone
✗ from pinecone import init
The `init` function was deprecated in `pinecone-client` v3.0.0; use the `Pinecone` class constructor instead.
This quickstart demonstrates how to initialize the Pinecone client, create a new Pinecone index (if it doesn't exist), embed documents using OpenAIEmbeddings, store them in the Pinecone vector store, and perform a similarity search. Ensure you have your `PINECONE_API_KEY`, `PINECONE_ENVIRONMENT`, and `OPENAI_API_KEY` set as environment variables or replaced in the code.
import os
from langchain_pinecone import PineconeVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain_core.documents import Document
from pinecone import Pinecone, ServerlessSpec
# --- Configuration (replace with your actual keys and environment) ---
# It's recommended to set these as environment variables.
PINECONE_API_KEY = os.environ.get("PINECONE_API_KEY", "YOUR_PINECONE_API_KEY")
PINECONE_ENVIRONMENT = os.environ.get("PINECONE_ENVIRONMENT", "gcp-starter") # e.g., 'us-west-2'
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "YOUR_OPENAI_API_KEY")
if PINECONE_API_KEY == "YOUR_PINECONE_API_KEY" or OPENAI_API_KEY == "YOUR_OPENAI_API_KEY":
print("Warning: Please set PINECONE_API_KEY and OPENAI_API_KEY environment variables.")
print("Quickstart will likely fail due to missing credentials.")
index_name = "my-langchain-test-index"
dimension = 1536 # OpenAI text-embedding-ada-002 model dimension
metric = "cosine"
# --- Initialize Pinecone Client (pinecone-client v3.x recommended) ---
try:
pc = Pinecone(api_key=PINECONE_API_KEY, environment=PINECONE_ENVIRONMENT)
except Exception as e:
print(f"Error initializing Pinecone client: {e}")
exit(1)
# --- Create/Connect to Pinecone Index ---
if index_name not in pc.list_indexes().names():
print(f"Creating Pinecone index '{index_name}'...")
pc.create_index(
name=index_name,
dimension=dimension,
metric=metric,
spec=ServerlessSpec(cloud="aws", region="us-west-2") # Adjust spec as needed
)
print(f"Index '{index_name}' created.")
else:
print(f"Connecting to existing Pinecone index '{index_name}'.")
# --- Initialize Embeddings Model ---
embeddings = OpenAIEmbeddings(api_key=OPENAI_API_KEY)
# --- Prepare Documents ---
documents = [
Document(page_content="The quick brown fox jumps over the lazy dog."),
Document(page_content="A computer is an electronic device that processes data."),
Document(page_content="LangChain is a framework for developing applications powered by language models."),
Document(page_content="Pinecone is a vector database for building AI applications.")
]
# --- Create or Connect to the Vector Store from Documents ---
# This method handles embedding and upserting the documents.
print("Adding documents to Pinecone vector store...")
vectorstore = PineconeVectorStore.from_documents(
documents, embeddings, index_name=index_name
)
print("Documents added.")
# --- Perform a Similarity Search ---
query = "What is LangChain?"
print(f"\nPerforming similarity search for: '{query}'")
results = vectorstore.similarity_search(query, k=1)
print("\nSearch Results:")
for doc in results:
print(f"- Content: {doc.page_content}")
# --- Optional: Clean up ---
# print(f"\nDeleting index '{index_name}' for cleanup...")
# pc.delete_index(index_name)
# print(f"Index '{index_name}' deleted.")
Debug
Known issues
breaking`pinecone-client` v3.0.0 introduced a breaking change to how the Pinecone client is initialized. The global `pinecone.init()` function was deprecated in favor of instantiating the `pinecone.Pinecone` class directly.fixReplace `from pinecone import init; init(api_key='...', environment='...')` with `from pinecone import Pinecone; pc = Pinecone(api_key='...', environment='...')`. Ensure your `langchain-pinecone` library is updated to leverage the newer client as well.
affects: pinecone-client <3.0.0 (old) vs pinecone-client >=3.0.0 (new)
gotchaMismatch between the embedding model's dimension and the Pinecone index's dimension. If the index is created with a dimension (e.g., 768 for `all-MiniLM-L6-v2`) and you try to insert vectors from an embedding model with a different dimension (e.g., 1536 for OpenAI `text-embedding-ada-002`), it will result in an error.fixAlways ensure the `dimension` parameter used when creating your Pinecone index matches the output dimension of your chosen embedding model. For OpenAI's `text-embedding-ada-002`, the dimension is 1536.
affects: All versions
gotchaIncorrect or missing Pinecone API key or environment configuration. This is a common setup issue that leads to authentication or connection errors.fixDouble-check your `PINECONE_API_KEY` and `PINECONE_ENVIRONMENT` (or the `api_key` and `environment` passed to `pinecone.Pinecone()`). Ensure the environment matches your Pinecone project's region (e.g., 'us-west-2', 'gcp-starter'). Using environment variables is recommended: `export PINECONE_API_KEY='...'`.
affects: All versions
gotchaWhen using `PineconeVectorStore.from_existing_index()`, the specified Pinecone index must already exist. If it does not, this method will raise an error.fixEnsure the index is created in Pinecone before calling `from_existing_index()`. If you want to create an index on the fly from documents, use `PineconeVectorStore.from_documents()` and pass the `index_name` parameter; it will create the index if it doesn't exist.
affects: All versions
deprecatedOlder versions of LangChain (prior to v0.1.x) might have provided integration classes directly under `langchain.vectorstores.Pinecone`. The recommended approach for LangChain v0.1.x and newer is to use the dedicated `langchain-pinecone` package.fixUpgrade your `langchain` and `langchain-pinecone` packages and use `from langchain_pinecone import PineconeVectorStore`. Migrate any direct imports from `langchain.vectorstores`.
affects: langchain <0.1.0
Upgrade
Version history
0.2.13latest on PyPI · released Nov 2, 2025
Audit
Dependencies
langchainrequiredCore LangChain library for application logic.
pinecone-clientrequiredOfficial Python client for interacting with Pinecone services.
langchain-openaioptionalCommon dependency for OpenAI embeddings, often used with Pinecone.