!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)
*   Neo4j Vector Index

On this page

Neo4j Vector Index
==================

Neo4j is an open-source graph database with integrated support for vector similarity search. It supports:

*   approximate nearest neighbor search
*   Euclidean similarity and cosine similarity
*   Hybrid search combining vector and keyword searches

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

To work with Neo4j Vector Index, you need to install the `neo4j-driver` package:

*   npm
*   Yarn
*   pnpm

    npm install neo4j-driver

    yarn add neo4j-driver

    pnpm add neo4j-driver

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

### Setup a `Neo4j` self hosted instance with `docker-compose`[​](#setup-a-neo4j-self-hosted-instance-with-docker-compose "Direct link to setup-a-neo4j-self-hosted-instance-with-docker-compose")

`Neo4j` provides a prebuilt Docker image that can be used to quickly setup a self-hosted Neo4j database instance. Create a file below named `docker-compose.yml`:

    export default {services:{database:{image:'neo4j',ports:['7687:7687','7474:7474'],environment:['NEO4J_AUTH=neo4j/pleaseletmein']}}};

#### API Reference:

And then in the same directory, run `docker compose up` to start the container.

You can find more information on how to setup `Neo4j` on their [website](https://neo4j.com/docs/operations-manual/current/installation/).

Usage[​](#usage "Direct link to Usage")
---------------------------------------

One complete example of using `Neo4jVectorStore` is the following:

    import { OpenAIEmbeddings } from "@langchain/openai";import { Neo4jVectorStore } from "@langchain/community/vectorstores/neo4j_vector";// Configuration object for Neo4j connection and other related settingsconst config = {  url: "bolt://localhost:7687", // URL for the Neo4j instance  username: "neo4j", // Username for Neo4j authentication  password: "pleaseletmein", // Password for Neo4j authentication  indexName: "vector", // Name of the vector index  keywordIndexName: "keyword", // Name of the keyword index if using hybrid search  searchType: "vector" as const, // Type of search (e.g., vector, hybrid)  nodeLabel: "Chunk", // Label for the nodes in the graph  textNodeProperty: "text", // Property of the node containing text  embeddingNodeProperty: "embedding", // Property of the node containing embedding};const documents = [  { pageContent: "what's this", metadata: { a: 2 } },  { pageContent: "Cat drinks milk", metadata: { a: 1 } },];const neo4jVectorIndex = await Neo4jVectorStore.fromDocuments(  documents,  new OpenAIEmbeddings(),  config);const results = await neo4jVectorIndex.similaritySearch("water", 1);console.log(results);/*  [ Document { pageContent: 'Cat drinks milk', metadata: { a: 1 } } ]*/await neo4jVectorIndex.close();

#### API Reference:

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

### Use retrievalQuery parameter to customize responses[​](#use-retrievalquery-parameter-to-customize-responses "Direct link to Use retrievalQuery parameter to customize responses")

    import { OpenAIEmbeddings } from "@langchain/openai";import { Neo4jVectorStore } from "@langchain/community/vectorstores/neo4j_vector";/* * The retrievalQuery is a customizable Cypher query fragment used in the Neo4jVectorStore class to define how * search results should be retrieved and presented from the Neo4j database. It allows developers to specify * the format and structure of the data returned after a similarity search. * Mandatory columns for `retrievalQuery`: * * 1. text: *    - Description: Represents the textual content of the node. *    - Type: String * * 2. score: *    - Description: Represents the similarity score of the node in relation to the search query. A *      higher score indicates a closer match. *    - Type: Float (ranging between 0 and 1, where 1 is a perfect match) * * 3. metadata: *    - Description: Contains additional properties and information about the node. This can include *      any other attributes of the node that might be relevant to the application. *    - Type: Object (key-value pairs) *    - Example: { "id": "12345", "category": "Books", "author": "John Doe" } * * Note: While you can customize the `retrievalQuery` to fetch additional columns or perform * transformations, never omit the mandatory columns. The names of these columns (`text`, `score`, * and `metadata`) should remain consistent. Renaming them might lead to errors or unexpected behavior. */// Configuration object for Neo4j connection and other related settingsconst config = {  url: "bolt://localhost:7687", // URL for the Neo4j instance  username: "neo4j", // Username for Neo4j authentication  password: "pleaseletmein", // Password for Neo4j authentication  retrievalQuery: `    RETURN node.text AS text, score, {a: node.a * 2} AS metadata  `,};const documents = [  { pageContent: "what's this", metadata: { a: 2 } },  { pageContent: "Cat drinks milk", metadata: { a: 1 } },];const neo4jVectorIndex = await Neo4jVectorStore.fromDocuments(  documents,  new OpenAIEmbeddings(),  config);const results = await neo4jVectorIndex.similaritySearch("water", 1);console.log(results);/*  [ Document { pageContent: 'Cat drinks milk', metadata: { a: 2 } } ]*/await neo4jVectorIndex.close();

#### API Reference:

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

### Instantiate Neo4jVectorStore from existing graph[​](#instantiate-neo4jvectorstore-from-existing-graph "Direct link to Instantiate Neo4jVectorStore from existing graph")

    import { OpenAIEmbeddings } from "@langchain/openai";import { Neo4jVectorStore } from "@langchain/community/vectorstores/neo4j_vector";/** * `fromExistingGraph` Method: * * Description: * This method initializes a `Neo4jVectorStore` instance using an existing graph in the Neo4j database. * It's designed to work with nodes that already have textual properties but might not have embeddings. * The method will compute and store embeddings for nodes that lack them. * * Note: * This method is particularly useful when you have a pre-existing graph with textual data and you want * to enhance it with vector embeddings for similarity searches without altering the original data structure. */// Configuration object for Neo4j connection and other related settingsconst config = {  url: "bolt://localhost:7687", // URL for the Neo4j instance  username: "neo4j", // Username for Neo4j authentication  password: "pleaseletmein", // Password for Neo4j authentication  indexName: "wikipedia",  nodeLabel: "Wikipedia",  textNodeProperties: ["title", "description"],  embeddingNodeProperty: "embedding",  searchType: "hybrid" as const,};// You should have a populated Neo4j database to use this methodconst neo4jVectorIndex = await Neo4jVectorStore.fromExistingGraph(  new OpenAIEmbeddings(),  config);await neo4jVectorIndex.close();

#### API Reference:

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

Disclaimer ⚠️
=============

_Security note_: Make sure that the database connection uses credentials that are narrowly-scoped to only include necessary permissions. Failure to do so may result in data corruption or loss, since the calling code may attempt commands that would result in deletion, mutation of data if appropriately prompted or reading sensitive data if such data is present in the database. The best way to guard against such negative outcomes is to (as appropriate) limit the permissions granted to the credentials used with this tool. For example, creating read only users for the database is a good way to ensure that the calling code cannot mutate or delete data. See the [security page](/v0.2/docs/security) for more information.

* * *

#### 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

MyScale

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

Next

Neon Postgres

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

*   [Setup](#setup)
    *   [Setup a `Neo4j` self hosted instance with `docker-compose`](#setup-a-neo4j-self-hosted-instance-with-docker-compose)
*   [Usage](#usage)
    *   [Use retrievalQuery parameter to customize responses](#use-retrievalquery-parameter-to-customize-responses)
    *   [Instantiate Neo4jVectorStore from existing graph](#instantiate-neo4jvectorstore-from-existing-graph)

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.