!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())

[Skip to main content](#__docusaurus_skipToContent_fallback)

LangChain v0.2 is coming soon! Preview the new docs [here](/v0.2/docs/introduction/).

[

![🦜️🔗 Langchain](/v0.1/img/brand/wordmark.png)![🦜️🔗 Langchain](/v0.1/img/brand/wordmark-dark.png)

](/v0.1/)[Docs](/v0.1/docs/get_started/introduction/)[Use cases](/v0.1/docs/use_cases/)[Integrations](/v0.1/docs/integrations/platforms/)[API Reference](https://api.js.langchain.com)

[More](#)

*   [People](/v0.1/docs/people/)
*   [Community](/v0.1/docs/community/)
*   [Tutorials](/v0.1/docs/additional_resources/tutorials/)
*   [Contributing](/v0.1/docs/contributing/)

[v0.1](#)

*   [v0.2](https://js.langchain.com/v0.2/docs/introduction)
*   [v0.1](/v0.1/docs/get_started/introduction/)

[🦜🔗](#)

*   [LangSmith](https://smith.langchain.com)
*   [LangSmith Docs](https://docs.smith.langchain.com)
*   [LangChain Hub](https://smith.langchain.com/hub)
*   [LangServe](https://github.com/langchain-ai/langserve)
*   [Python Docs](https://python.langchain.com/)

[Chat](https://chatjs.langchain.com)[](https://github.com/langchain-ai/langchainjs)

Search

*   [Providers](/v0.1/docs/integrations/platforms/)
    
    *   [Providers](/v0.1/docs/integrations/platforms/)
    *   [Anthropic](/v0.1/docs/integrations/platforms/anthropic/)
    *   [AWS](/v0.1/docs/integrations/platforms/aws/)
    *   [Google](/v0.1/docs/integrations/platforms/google/)
    *   [Microsoft](/v0.1/docs/integrations/platforms/microsoft/)
    *   [OpenAI](/v0.1/docs/integrations/platforms/openai/)
*   [Components](/v0.1/docs/integrations/components/)
    
    *   [LLMs](/v0.1/docs/integrations/llms/)
        
    *   [Chat models](/v0.1/docs/integrations/chat/)
        
    *   [Document loaders](/v0.1/docs/integrations/document_loaders/)
        
    *   [Document transformers](/v0.1/docs/integrations/document_transformers/)
        
    *   [Document compressors](/v0.1/docs/integrations/document_compressors/)
        
    *   [Text embedding models](/v0.1/docs/integrations/text_embedding/)
        
    *   [Vector stores](/v0.1/docs/integrations/vectorstores/)
        
        *   [Memory](/v0.1/docs/integrations/vectorstores/memory/)
        *   [AnalyticDB](/v0.1/docs/integrations/vectorstores/analyticdb/)
        *   [Astra DB](/v0.1/docs/integrations/vectorstores/astradb/)
        *   [Azure AI Search](/v0.1/docs/integrations/vectorstores/azure_aisearch/)
        *   [Azure Cosmos DB](/v0.1/docs/integrations/vectorstores/azure_cosmosdb/)
        *   [Cassandra](/v0.1/docs/integrations/vectorstores/cassandra/)
        *   [Chroma](/v0.1/docs/integrations/vectorstores/chroma/)
        *   [ClickHouse](/v0.1/docs/integrations/vectorstores/clickhouse/)
        *   [CloseVector](/v0.1/docs/integrations/vectorstores/closevector/)
        *   [Cloudflare Vectorize](/v0.1/docs/integrations/vectorstores/cloudflare_vectorize/)
        *   [Convex](/v0.1/docs/integrations/vectorstores/convex/)
        *   [Couchbase](/v0.1/docs/integrations/vectorstores/couchbase/)
        *   [Elasticsearch](/v0.1/docs/integrations/vectorstores/elasticsearch/)
        *   [Faiss](/v0.1/docs/integrations/vectorstores/faiss/)
        *   [Google Vertex AI Matching Engine](/v0.1/docs/integrations/vectorstores/googlevertexai/)
        *   [SAP HANA Cloud Vector Engine](/v0.1/docs/integrations/vectorstores/hanavector/)
        *   [HNSWLib](/v0.1/docs/integrations/vectorstores/hnswlib/)
        *   [LanceDB](/v0.1/docs/integrations/vectorstores/lancedb/)
        *   [Milvus](/v0.1/docs/integrations/vectorstores/milvus/)
        *   [Momento Vector Index (MVI)](/v0.1/docs/integrations/vectorstores/momento_vector_index/)
        *   [MongoDB Atlas](/v0.1/docs/integrations/vectorstores/mongodb_atlas/)
        *   [MyScale](/v0.1/docs/integrations/vectorstores/myscale/)
        *   [Neo4j Vector Index](/v0.1/docs/integrations/vectorstores/neo4jvector/)
        *   [Neon Postgres](/v0.1/docs/integrations/vectorstores/neon/)
        *   [OpenSearch](/v0.1/docs/integrations/vectorstores/opensearch/)
        *   [PGVector](/v0.1/docs/integrations/vectorstores/pgvector/)
        *   [Pinecone](/v0.1/docs/integrations/vectorstores/pinecone/)
        *   [Prisma](/v0.1/docs/integrations/vectorstores/prisma/)
        *   [Qdrant](/v0.1/docs/integrations/vectorstores/qdrant/)
        *   [Redis](/v0.1/docs/integrations/vectorstores/redis/)
        *   [Rockset](/v0.1/docs/integrations/vectorstores/rockset/)
        *   [SingleStore](/v0.1/docs/integrations/vectorstores/singlestore/)
        *   [Supabase](/v0.1/docs/integrations/vectorstores/supabase/)
        *   [Tigris](/v0.1/docs/integrations/vectorstores/tigris/)
        *   [Turbopuffer](/v0.1/docs/integrations/vectorstores/turbopuffer/)
        *   [TypeORM](/v0.1/docs/integrations/vectorstores/typeorm/)
        *   [Typesense](/v0.1/docs/integrations/vectorstores/typesense/)
        *   [Upstash Vector](/v0.1/docs/integrations/vectorstores/upstash/)
        *   [USearch](/v0.1/docs/integrations/vectorstores/usearch/)
        *   [Vectara](/v0.1/docs/integrations/vectorstores/vectara/)
        *   [Vercel Postgres](/v0.1/docs/integrations/vectorstores/vercel_postgres/)
        *   [Voy](/v0.1/docs/integrations/vectorstores/voy/)
        *   [Weaviate](/v0.1/docs/integrations/vectorstores/weaviate/)
        *   [Xata](/v0.1/docs/integrations/vectorstores/xata/)
        *   [Zep](/v0.1/docs/integrations/vectorstores/zep/)
    *   [Retrievers](/v0.1/docs/integrations/retrievers/)
        
    *   [Tools](/v0.1/docs/integrations/tools/)
        
    *   [Agents and toolkits](/v0.1/docs/integrations/toolkits/)
        
    *   [Chat Memory](/v0.1/docs/integrations/chat_memory/)
        
    *   [Stores](/v0.1/docs/integrations/stores/)
        

*   [](/v0.1/)
*   [Components](/v0.1/docs/integrations/components/)
*   [Vector stores](/v0.1/docs/integrations/vectorstores/)
*   Pinecone

On this page

Pinecone
========

You can use [Pinecone](https://www.pinecone.io/) vectorstores with LangChain. To get started, install the integration package and the official Pinecone SDK with:

tip

See [this section for general instructions on installing integration packages](/v0.1/docs/get_started/installation/#installing-integration-packages).

*   npm
*   Yarn
*   pnpm

    npm install -S @langchain/pinecone @pinecone-database/pinecone

    yarn add @langchain/pinecone @pinecone-database/pinecone

    pnpm add @langchain/pinecone @pinecone-database/pinecone

The below examples use OpenAI embeddings, but you can swap in whichever provider you'd like. Keep in mind different embeddings models may have a different number of dimensions:

*   npm
*   Yarn
*   pnpm

    npm install -S @langchain/openai

    yarn add @langchain/openai

    pnpm add @langchain/openai

Index docs[​](#index-docs "Direct link to Index docs")
------------------------------------------------------

    /* eslint-disable @typescript-eslint/no-non-null-assertion */import { Pinecone } from "@pinecone-database/pinecone";import { Document } from "@langchain/core/documents";import { OpenAIEmbeddings } from "@langchain/openai";import { PineconeStore } from "@langchain/pinecone";// Instantiate a new Pinecone client, which will automatically read the// env vars: PINECONE_API_KEY and PINECONE_ENVIRONMENT which come from// the Pinecone dashboard at https://app.pinecone.ioconst pinecone = new Pinecone();const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX!);const docs = [  new Document({    metadata: { foo: "bar" },    pageContent: "pinecone is a vector db",  }),  new Document({    metadata: { foo: "bar" },    pageContent: "the quick brown fox jumped over the lazy dog",  }),  new Document({    metadata: { baz: "qux" },    pageContent: "lorem ipsum dolor sit amet",  }),  new Document({    metadata: { baz: "qux" },    pageContent: "pinecones are the woody fruiting body and of a pine tree",  }),];await PineconeStore.fromDocuments(docs, new OpenAIEmbeddings(), {  pineconeIndex,  maxConcurrency: 5, // Maximum number of batch requests to allow at once. Each batch is 1000 vectors.});

#### API Reference:

*   [Document](https://api.js.langchain.com/classes/langchain_core_documents.Document.html) from `@langchain/core/documents`
*   [OpenAIEmbeddings](https://api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [PineconeStore](https://api.js.langchain.com/classes/langchain_pinecone.PineconeStore.html) from `@langchain/pinecone`

Query docs[​](#query-docs "Direct link to Query docs")
------------------------------------------------------

    /* eslint-disable @typescript-eslint/no-non-null-assertion */import { Pinecone } from "@pinecone-database/pinecone";import { OpenAIEmbeddings } from "@langchain/openai";import { PineconeStore } from "@langchain/pinecone";// Instantiate a new Pinecone client, which will automatically read the// env vars: PINECONE_API_KEY and PINECONE_ENVIRONMENT which come from// the Pinecone dashboard at https://app.pinecone.ioconst pinecone = new Pinecone();const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX!);const vectorStore = await PineconeStore.fromExistingIndex(  new OpenAIEmbeddings(),  { pineconeIndex });/* Search the vector DB independently with metadata filters */const results = await vectorStore.similaritySearch("pinecone", 1, {  foo: "bar",});console.log(results);/*  [    Document {      pageContent: 'pinecone is a vector db',      metadata: { foo: 'bar' }    }  ]*/

#### API Reference:

*   [OpenAIEmbeddings](https://api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [PineconeStore](https://api.js.langchain.com/classes/langchain_pinecone.PineconeStore.html) from `@langchain/pinecone`

Delete docs[​](#delete-docs "Direct link to Delete docs")
---------------------------------------------------------

    /* eslint-disable @typescript-eslint/no-non-null-assertion */import { Pinecone } from "@pinecone-database/pinecone";import { Document } from "@langchain/core/documents";import { OpenAIEmbeddings } from "@langchain/openai";import { PineconeStore } from "@langchain/pinecone";// Instantiate a new Pinecone client, which will automatically read the// env vars: PINECONE_API_KEY and PINECONE_ENVIRONMENT which come from// the Pinecone dashboard at https://app.pinecone.ioconst pinecone = new Pinecone();const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX!);const embeddings = new OpenAIEmbeddings();const pineconeStore = new PineconeStore(embeddings, { pineconeIndex });const docs = [  new Document({    metadata: { foo: "bar" },    pageContent: "pinecone is a vector db",  }),  new Document({    metadata: { foo: "bar" },    pageContent: "the quick brown fox jumped over the lazy dog",  }),  new Document({    metadata: { baz: "qux" },    pageContent: "lorem ipsum dolor sit amet",  }),  new Document({    metadata: { baz: "qux" },    pageContent: "pinecones are the woody fruiting body and of a pine tree",  }),];const pageContent = "some arbitrary content";// Also takes an additional {ids: []} parameter for upsertionconst ids = await pineconeStore.addDocuments(docs);const results = await pineconeStore.similaritySearch(pageContent, 2, {  foo: "bar",});console.log(results);/*[  Document {    pageContent: 'pinecone is a vector db',    metadata: { foo: 'bar' },  },  Document {    pageContent: "the quick brown fox jumped over the lazy dog",    metadata: { foo: "bar" },  }]*/await pineconeStore.delete({  ids: [ids[0], ids[1]],});const results2 = await pineconeStore.similaritySearch(pageContent, 2, {  foo: "bar",});console.log(results2);/*  []*/

#### API Reference:

*   [Document](https://api.js.langchain.com/classes/langchain_core_documents.Document.html) from `@langchain/core/documents`
*   [OpenAIEmbeddings](https://api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [PineconeStore](https://api.js.langchain.com/classes/langchain_pinecone.PineconeStore.html) from `@langchain/pinecone`

Maximal marginal relevance search[​](#maximal-marginal-relevance-search "Direct link to Maximal marginal relevance search")
---------------------------------------------------------------------------------------------------------------------------

Pinecone supports maximal marginal relevance search, which takes a combination of documents that are most similar to the inputs, then reranks and optimizes for diversity.

    /* eslint-disable @typescript-eslint/no-non-null-assertion */import { Pinecone } from "@pinecone-database/pinecone";import { OpenAIEmbeddings } from "@langchain/openai";import { PineconeStore } from "@langchain/pinecone";// Instantiate a new Pinecone client, which will automatically read the// env vars: PINECONE_API_KEY and PINECONE_ENVIRONMENT which come from// the Pinecone dashboard at https://app.pinecone.ioconst pinecone = new Pinecone();const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX!);const vectorStore = await PineconeStore.fromExistingIndex(  new OpenAIEmbeddings(),  { pineconeIndex });/* Search the vector DB independently with meta filters */const results = await vectorStore.maxMarginalRelevanceSearch("pinecone", {  k: 5,  fetchK: 20, // Default value for the number of initial documents to fetch for reranking.  // You can pass a filter as well  // filter: {},});console.log(results);

#### API Reference:

*   [OpenAIEmbeddings](https://api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [PineconeStore](https://api.js.langchain.com/classes/langchain_pinecone.PineconeStore.html) from `@langchain/pinecone`

* * *

#### Help us out by providing feedback on this documentation page:

[

Previous

PGVector

](/v0.1/docs/integrations/vectorstores/pgvector/)[

Next

Prisma

](/v0.1/docs/integrations/vectorstores/prisma/)

*   [Index docs](#index-docs)
*   [Query docs](#query-docs)
*   [Delete docs](#delete-docs)
*   [Maximal marginal relevance search](#maximal-marginal-relevance-search)

Community

*   [Discord](https://discord.gg/cU2adEyC7w)
*   [Twitter](https://twitter.com/LangChainAI)

GitHub

*   [Python](https://github.com/langchain-ai/langchain)
*   [JS/TS](https://github.com/langchain-ai/langchainjs)

More

*   [Homepage](https://langchain.com)
*   [Blog](https://blog.langchain.dev)

Copyright © 2024 LangChain, Inc.