Skip to main content

Usage

from langchat.providers import Pinecone

vector_db = Pinecone("my-index")   # reads PINECONE_API_KEY + OPENAI_API_KEY

Parameters

index
str
required
Pinecone index name. First positional argument.
api_key
str | None
default:"None"
Pinecone API key. Falls back to PINECONE_API_KEY.
embedding_api_key
str | None
default:"None"
OpenAI API key used for creating embeddings. Falls back to OPENAI_API_KEY.
embedding_model
str
default:"text-embedding-3-large"
OpenAI embedding model for both indexing and retrieval.

Environment variables

PINECONE_API_KEY=pcsk-...
OPENAI_API_KEY=sk-...    # used for embeddings

Embedding models

ModelDimensionsNotes
text-embedding-3-large3072Default. Best quality.
text-embedding-3-small1536Lower cost, still good quality.
text-embedding-ada-0021536Legacy baseline.
Your Pinecone index dimensions must match the embedding model:
  • text-embedding-3-large → create index with 3072 dimensions
  • text-embedding-3-small → create index with 1536 dimensions
Change the embedding model:
vector_db = Pinecone("my-index", embedding_model="text-embedding-3-small")

Creating a Pinecone index

  1. Go to app.pinecone.io
  2. Create a Serverless index:
    • Dimensions: 3072 (for text-embedding-3-large)
    • Metric: cosine
    • Cloud/Region: choose based on your API server location
  3. Copy the index name and your API key to .env

Namespaces

Use namespaces to partition a single index into logical sections:
# Index with namespace
lc.index("products/", namespace="products")
lc.index("support/", namespace="support")
The retriever uses the namespace you configured when creating the Pinecone instance. For multi-namespace retrieval, you need separate LangChat instances or a custom adapter.