Neo4j GraphRAG

Neo4j GraphRAG 是一个用于使用 Neo4j 和 Python 构建图检索增强生成 (GraphRAG) 应用程序的 Python 包。作为一个第一方库,它提供了一个强大、功能丰富且高性能的解决方案,并有 Neo4j 直接提供的长期支持和维护保证。它原生提供了一个 Qdrant 检索器,用于搜索存储在 Qdrant 集合中的向量。

安装

pip install neo4j-graphrag[qdrant]

使用方法

使用 Neo4j 和 Qdrant 的向量查询示例如下:

from neo4j import GraphDatabase
from neo4j_graphrag.retrievers import QdrantNeo4jRetriever
from qdrant_client import QdrantClient
from examples.embedding_biology import EMBEDDING_BIOLOGY

NEO4J_URL = "neo4j://localhost:7687"
NEO4J_AUTH = ("neo4j", "password")

with GraphDatabase.driver(NEO4J_URL, auth=NEO4J_AUTH) as neo4j_driver:
    retriever = QdrantNeo4jRetriever(
        driver=neo4j_driver,
        client=QdrantClient(url="http://localhost:6333"),
        collection_name="{collection_name}",
        id_property_external="neo4j_id",
        id_property_neo4j="id",
    )

retriever.search(query_vector=[0.5523, 0.523, 0.132, 0.523, ...], top_k=5)

或者,您可以使用任何 Langchain 嵌入提供商,自动将文本查询向量化。

from langchain_huggingface.embeddings import HuggingFaceEmbeddings
from neo4j import GraphDatabase
from neo4j_graphrag.retrievers import QdrantNeo4jRetriever
from qdrant_client import QdrantClient

NEO4J_URL = "neo4j://localhost:7687"
NEO4J_AUTH = ("neo4j", "password")

with GraphDatabase.driver(NEO4J_URL, auth=NEO4J_AUTH) as neo4j_driver:
    embedder = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
    retriever = QdrantNeo4jRetriever(
        driver=neo4j_driver,
        client=QdrantClient(url="http://localhost:6333"),
        collection_name="{collection_name}",
        id_property_external="neo4j_id",
        id_property_neo4j="id",
        embedder=embedder,
    )

retriever.search(query_text="my user query", top_k=10)

延伸阅读

此页面有用吗?

感谢您的反馈!🙏

我们很抱歉听到这个消息。😔 您可以在 GitHub 上编辑此页面,或创建一个 GitHub 问题。