!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)

You are viewing the **preview** v0.2 docs. View the **stable** v0.1 docs [here](/v0.1/docs/get_started/introduction/). Leave feedback on the v0.2 docs [here](https://github.com/langchain-ai/langchainjs/discussions/5386).

[

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

](/v0.2/)[Integrations](/v0.2/docs/integrations/platforms/)[API Reference](https://v02.api.js.langchain.com)

[More](#)

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

[v0.2](#)

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

*   [](/v0.2/)
*   [Components](/v0.2/docs/integrations/components)
*   [Vector stores](/v0.2/docs/integrations/vectorstores)
*   Upstash Vector

On this page

Upstash Vector
==============

Upstash Vector is a REST based serverless vector database, designed for working with vector embeddings.

Setup[​](#setup "Direct link to Setup")
---------------------------------------

1.  Create Upstash Vector Index

You can create an index from [Upstash Console](https://console.upstash.com/vector). For further reference, see [docs](https://upstash.com/docs/vector/overall/getstarted).

2.  Install Upstash Vector SDK.

*   npm
*   Yarn
*   pnpm

    npm install -S @upstash/vector

    yarn add @upstash/vector

    pnpm add @upstash/vector

We use OpenAI for the embeddings of the below examples. However, you can also create the embeddings using the model of your choice, that is available in the LangChain.

tip

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

*   npm
*   Yarn
*   pnpm

    npm install @langchain/openai @langchain/community

    yarn add @langchain/openai @langchain/community

    pnpm add @langchain/openai @langchain/community

Create Upstash Vector Client[​](#create-upstash-vector-client "Direct link to Create Upstash Vector Client")
------------------------------------------------------------------------------------------------------------

There are two ways to create the client. You can either pass the credentials as string manually from the `.env` file (or as string variables), or you can retrieve the credentials from the environment automatically.

    import { Index } from "@upstash/vector";import { OpenAIEmbeddings } from "@langchain/openai";import { UpstashVectorStore } from "@langchain/community/vectorstores/upstash";const embeddings = new OpenAIEmbeddings({});// Creating the index with the provided credentials.const indexWithCredentials = new Index({  url: process.env.UPSTASH_VECTOR_REST_URL as string,  token: process.env.UPSTASH_VECTOR_REST_TOKEN as string,});const storeWithCredentials = new UpstashVectorStore(embeddings, {  index: indexWithCredentials,});// Creating the index from the environment variables automatically.const indexFromEnv = new Index();const storeFromEnv = new UpstashVectorStore(embeddings, {  index: indexFromEnv,});

#### API Reference:

*   [OpenAIEmbeddings](https://v02.api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [UpstashVectorStore](https://v02.api.js.langchain.com/classes/langchain_community_vectorstores_upstash.UpstashVectorStore.html) from `@langchain/community/vectorstores/upstash`

Index and Query Documents[​](#index-and-query-documents "Direct link to Index and Query Documents")
---------------------------------------------------------------------------------------------------

You can index the LangChain documents with any model of your choice, and perform a search over these documents. It's possible to apply metadata filtering to the search results. See [the related docs here](https://upstash.com/docs/vector/features/filtering).

    import { Index } from "@upstash/vector";import { OpenAIEmbeddings } from "@langchain/openai";import { Document } from "@langchain/core/documents";import { UpstashVectorStore } from "@langchain/community/vectorstores/upstash";const index = new Index({  url: process.env.UPSTASH_VECTOR_REST_URL as string,  token: process.env.UPSTASH_VECTOR_REST_TOKEN as string,});const embeddings = new OpenAIEmbeddings({});const UpstashVector = new UpstashVectorStore(embeddings, { index });// Creating the docs to be indexed.const id = new Date().getTime();const documents = [  new Document({    metadata: { name: id },    pageContent: "Hello there!",  }),  new Document({    metadata: { name: id },    pageContent: "What are you building?",  }),  new Document({    metadata: { time: id },    pageContent: "Upstash Vector is great for building AI applications.",  }),  new Document({    metadata: { time: id },    pageContent: "To be, or not to be, that is the question.",  }),];// Creating embeddings from the provided documents, and adding them to Upstash database.await UpstashVector.addDocuments(documents);// Waiting vectors to be indexed in the vector store.// eslint-disable-next-line no-promise-executor-returnawait new Promise((resolve) => setTimeout(resolve, 1000));const queryResult = await UpstashVector.similaritySearchWithScore(  "Vector database",  2);console.log(queryResult);/**[  [    Document {      pageContent: 'Upstash Vector is great for building AI applications.',      metadata: [Object]    },    0.9016147  ],  [    Document {      pageContent: 'What are you building?',      metadata: [Object]    },    0.8613077  ]] */

#### API Reference:

*   [OpenAIEmbeddings](https://v02.api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [Document](https://v02.api.js.langchain.com/classes/langchain_core_documents.Document.html) from `@langchain/core/documents`
*   [UpstashVectorStore](https://v02.api.js.langchain.com/classes/langchain_community_vectorstores_upstash.UpstashVectorStore.html) from `@langchain/community/vectorstores/upstash`

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

You can also delete the documents you've indexed previously.

    import { Index } from "@upstash/vector";import { OpenAIEmbeddings } from "@langchain/openai";import { UpstashVectorStore } from "@langchain/community/vectorstores/upstash";const index = new Index({  url: process.env.UPSTASH_VECTOR_REST_URL as string,  token: process.env.UPSTASH_VECTOR_REST_TOKEN as string,});const embeddings = new OpenAIEmbeddings({});const UpstashVector = new UpstashVectorStore(embeddings, { index });// Creating the docs to be indexed.const createdAt = new Date().getTime();const IDs = await UpstashVector.addDocuments([  { pageContent: "hello", metadata: { a: createdAt + 1 } },  { pageContent: "car", metadata: { a: createdAt } },  { pageContent: "adjective", metadata: { a: createdAt } },  { pageContent: "hi", metadata: { a: createdAt } },]);// Waiting vectors to be indexed in the vector store.// eslint-disable-next-line no-promise-executor-returnawait new Promise((resolve) => setTimeout(resolve, 1000));await UpstashVector.delete({ ids: [IDs[0], IDs[2], IDs[3]] });

#### API Reference:

*   [OpenAIEmbeddings](https://v02.api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [UpstashVectorStore](https://v02.api.js.langchain.com/classes/langchain_community_vectorstores_upstash.UpstashVectorStore.html) from `@langchain/community/vectorstores/upstash`

* * *

#### Was this page helpful?

  

#### You can leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchainjs/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Previous

Typesense

](/v0.2/docs/integrations/vectorstores/typesense)[

Next

USearch

](/v0.2/docs/integrations/vectorstores/usearch)

*   [Setup](#setup)
*   [Create Upstash Vector Client](#create-upstash-vector-client)
*   [Index and Query Documents](#index-and-query-documents)
*   [Delete Documents](#delete-documents)

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.