Skip to main content

LangChain graph store and vector store backed by GrafeoDB embedded graph database

Project description

CI codecov PyPI License

grafeo-langchain

LangChain graph store and vector store backed by GrafeoDB — an embedded graph database with native vector search.

No servers, no Docker, no configuration. Just pip install and go.

Install

pip install grafeo-langchain

Quick Start

Knowledge Graph (GraphStore)

Store LLM-extracted triples and query them with GQL/Cypher:

from langchain_openai import ChatOpenAI
from langchain_experimental.graph_transformers import LLMGraphTransformer
from langchain_core.documents import Document
from grafeo_langchain import GrafeoGraphStore

llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
transformer = LLMGraphTransformer(llm=llm)

documents = [
    Document(page_content="Alice works at Microsoft. Bob works at Google. Alice knows Bob."),
]
graph_documents = transformer.convert_to_graph_documents(documents)

store = GrafeoGraphStore(db_path="./knowledge.db")
store.add_graph_documents(graph_documents, include_source=True)

results = store.query("MATCH (p:Person)-[:WORKS_AT]->(c) RETURN p.node_id, c.node_id")
print(store.get_schema)

Vector + Graph Retrieval (GraphVectorStore)

Combine vector similarity search with graph traversal for Graph RAG:

from langchain_openai import OpenAIEmbeddings
from grafeo_langchain import GrafeoGraphVectorStore

embeddings = OpenAIEmbeddings(model="text-embedding-3-small")
store = GrafeoGraphVectorStore(
    embedding=embeddings,
    db_path="./doc_graph.db",
    embedding_dimensions=1536,
)

store.add_texts(
    texts=["Python is a programming language...", "Guido van Rossum...", "ABC influenced..."],
    metadatas=[
        {"id": "python", "__graph_links__": [{"target_id": "abc", "type": "INFLUENCED_BY"}]},
        {"id": "guido"},
        {"id": "abc", "__graph_links__": [{"target_id": "python", "type": "INFLUENCED"}]},
    ],
    ids=["python", "guido", "abc"],
)

# Standard vector search
docs = store.similarity_search("What programming languages exist?", k=2)

# Vector search + graph traversal
docs = store.traversal_search("What programming languages exist?", k=4, depth=2)

# MMR-diversified graph traversal
docs = store.mmr_traversal_search("programming history", k=4, depth=2, lambda_mult=0.7)

Why Grafeo?

Feature Neo4j Grafeo
Requires server Yes (Docker/Cloud) No (embedded, pip install)
GraphStore Yes Yes
GraphVectorStore Community package Built-in (native HNSW)
Query language Cypher GQL + Cypher + Gremlin
Graph algorithms GDS plugin ($$$) Built-in (PageRank, Louvain, ...)
Deployment Docker container Single .db file
Offline/edge No Yes

API Reference

GrafeoGraphStore

  • GrafeoGraphStore(db_path=None) — in-memory or persistent graph store
  • .add_graph_documents(docs, include_source=False) — ingest LLM-extracted graph documents
  • .query(query, params=None) — execute GQL/Cypher queries
  • .get_schema / .get_structured_schema — inspect the graph schema
  • .refresh_schema() — refresh the cached schema
  • .client — access the underlying GrafeoDB instance

GrafeoGraphVectorStore

  • GrafeoGraphVectorStore(embedding, db_path=None, embedding_dimensions=1536) — vector store with graph links
  • .add_texts(texts, metadatas=None, ids=None) — add documents with embeddings and optional graph links
  • .similarity_search(query, k=4) — standard vector similarity search
  • .traversal_search(query, k=4, depth=1) — vector search + graph traversal
  • .mmr_traversal_search(query, k=4, depth=2, fetch_k=100, lambda_mult=0.5) — MMR-diversified traversal
  • .from_texts(...) / .from_documents(...) — factory methods

Requirements

  • Python 3.12+

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grafeo_langchain-0.1.1.tar.gz (79.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grafeo_langchain-0.1.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file grafeo_langchain-0.1.1.tar.gz.

File metadata

  • Download URL: grafeo_langchain-0.1.1.tar.gz
  • Upload date:
  • Size: 79.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for grafeo_langchain-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f558b0c6d871d16d0f4b563a1b57d2b88d1b7355cad58252dc2ae4b1bdb0f5c
MD5 3d49511a481dee549d5f46c262a3efc1
BLAKE2b-256 11cab5cd7832bcf110b7e69234cd521ab81e976485ebcb2c109094d4dab25224

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo_langchain-0.1.1.tar.gz:

Publisher: pypi.yml on GrafeoDB/grafeo-langchain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grafeo_langchain-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for grafeo_langchain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4229d57efee6d9b3fd6f854cab77645747ba04549474a9460465bba565e3b516
MD5 f0713c30c4c5291bc2177dc3156a1d3e
BLAKE2b-256 7ff641b87dd68ce303f71418834cb22ed5b72118ea4d1f29a6624a5bab79bee3

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo_langchain-0.1.1-py3-none-any.whl:

Publisher: pypi.yml on GrafeoDB/grafeo-langchain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page