LangChain graph store and vector store backed by GrafeoDB embedded graph database
Project description
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 underlyingGrafeoDBinstance
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grafeo_langchain-0.1.0.tar.gz.
File metadata
- Download URL: grafeo_langchain-0.1.0.tar.gz
- Upload date:
- Size: 87.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ea4d84c04cecc8ce338ff47e551c95725d62481b9a00e29f574e4eabb26b6c9
|
|
| MD5 |
923312650da8901a75f35456b6763fa7
|
|
| BLAKE2b-256 |
948e11e75376a669bf8e3132d754735dbcd61218f0f81fa1fc8e3c4fa407293e
|
File details
Details for the file grafeo_langchain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: grafeo_langchain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8731bbae543095b5e49ce67b44a212b8339402506cb0c09ff51d7fdf9ed6f40
|
|
| MD5 |
5e198cbfb31ea88dde4ed391e622aff9
|
|
| BLAKE2b-256 |
0d395dbdd858ee5a2ea07e404573bf5ff47dffd741fa8efb1752cbb7d56d1524
|