LangChain-Neo4j Partner Package: Officially Supported GraphRAG


LangChain-Neo4j Partner Package: Officially Supported GraphRAG


Announcing langchain-neo4j, the official partner package integrating Neo4j GraphRAG with the LangChain ecosystem. GraphRAG combines the power of knowledge graphs with Retrieval-Augmented Generation (RAG), multiplying the depth and breadth of answerable questions from the same source data.

LangChain is an open-source framework used by millions of developers to build GenAI applications. With community-driven integrations, LangChain users have already had their choice of components. LangChain v0.2 introduced new partner packages, which are co-maintained integrations with technology partners.

The latest one, langchain-neo4j, brings Neo4j features to LangChain users.

Why Neo4j GraphRAG for AI Apps?

Neo4j is great for building AI applications:

  • Graph-Based Data Representation: Neo4j’s graph database represents data as nodes and relationships, which is a natural way to model a mix of unstructured and structured data. These connections reveal patterns that provide better answers.
  • Efficient Querying: Neo4j’s query language, Cypher, is designed for pattern matching and allows for efficient querying across text chunks and data records.
  • Scalability and Flexibility: Neo4j can scale to handle large datasets and is flexible enough to support various AI use cases.

How langchain-neo4j Works

The langchain-neo4j package provides several key features that facilitate seamless integration between LangChain and Neo4j:

  • Neo4jGraph: A simple interface for interacting directly with a Neo4j database using Neo4j’s Python driver. It allows you to execute Cypher queries and retrieve data from the database.
  • Neo4jChatMessageHistory: Store and manage chat message history in a Neo4j database. The history represents messages as nodes and relationships, enabling efficient querying and analysis of conversation history.
  • Neo4jVector: This class enables you to create, manage, and query a Neo4j vector store. You can add high-dimensional vector embeddings to the store and perform similarity searches to find relevant information.
  • GraphCypherQAChain: This class facilitates natural language interactions with a Neo4j database. It leverages an LLM to translate user questions into Cypher queries, executes them against the database, and uses the results to generate natural language responses.

For users, the change is importing from a different package, without code changes.

pip install -U langchain-neo4j

Code that had imported Neo4jGraph from the langchain_community namespace…

from langchain_community.graphs import Neo4jGraph

becomes…

from langchain_neo4j import Neo4jGraph

Get Started with GraphRAG

The langchain-neo4j package provides a powerful toolkit for building AI applications that leverage the strengths of both LangChain and Neo4j. By combining the flexibility of LangChain with the graph-based capabilities of Neo4j, developers can create AI apps that are more intelligent, efficient, and scalable.

You can visit the langchain-neo4j package repository or head over to GraphAcademy to learn the fundamentals of GraphRAG.