Kglite

Embedded Cypher knowledge graph for Python and Rust. Bundled MCP server, describe() schema, and code-graph parser for LLM agents.

LLM Mart 9 views 687k listing impressions

KGLite is an embedded, Cypher-queryable knowledge graph for Python and Rust. The same graph can serve an application, an analyst, or an LLM agent. The Python wheel has no required Python runtime dependencies. The graph engine runs in-process without an external database service. Every crate ships under MIT. If you are embedding a graph engine in something you distribute, see Licensing and embedded distribution.

Quick Start

pip install kglite             # the DataFrame walk-through below assumes pandas
pip install fastembed          # (or sentence-transformers) bring-your-own embedder for text_score()
import pandas as pd
import kglite

# Three storage modes, picked by graph size: default (in-memory) is fastest,
# storage="mapped" mmaps columns as you grow, storage="disk", path=… goes to
# 100M+ nodes, Wikidata-scale, loaded lazily.
graph = kglite.KnowledgeGraph()

# Bulk-load nodes from a DataFrame.
people = pd.DataFrame({
    "id":   ["alice", "bob", "eve"],   "name": ["Alice", "Bob", "Eve"],
    "age":  [28, 35, 41],              "city": ["Oslo", "Bergen", "Trondheim"],
})
graph.add_nodes(people, node_type="Person", unique_id_field="id", node_title_field="name")

# Bulk-load relationships the same way.
knows = pd.DataFrame({"src": ["alice", "bob"], "tgt": ["bob", "eve"]})
graph.add_relationships(knows, connection_type="KNOWS",
                      source_type="Person", source_id_field="src",
                      target_type="Person", target_id_field="tgt")

# Query: returns a ResultView; eligible projections stay lazy until accessed.
for row in graph.cypher("""
    MATCH (p:Person) WHERE p.age > 30
    RETURN p.name AS name, p.city AS city
    ORDER BY p.age DESC
"""):
    print(row['name'], row['city'])

# Or get a pandas DataFrame directly.
df = graph.cypher("MATCH (p:Person) RETURN p.name, p.age ORDER BY p.age", to_df=True)

# Persist and reload. save() is atomic + fsync by default (crash-safe, no torn
# file); load() raises a typed kglite.FileFormatError on a corrupt file.
graph.save("my_graph.kgl")
loaded = kglite.load("my_graph.kgl")
blob = graph.to_bytes(); loaded = kglite.from_bytes(blob)   # or without a path

# Immutable, lock-free snapshot: concurrent snapshot.cypher(...) from many threads.
snapshot = graph.freeze()

# No data yet? A realistic demo graph in one line (bundled, no extra deps):
demo = kglite.graphgen("medium")               # ~25k nodes, ready to query

Then hand the same file to an agent. The MCP server is bundled in the wheel:

kglite-mcp-server --graph my_graph.kgl

→ MCP servers guide · CLI guide. Prefer a runnable file? examples/csv_to_graph.py loads real CSVs end to end.

Large agent results are bounded with targeted expansion. MCP offers session-local controls; CLI --format agent retrieves retained values later without rerunning the query. JSON and CSV remain complete. See Bounded agent responses.

Two guides cover most first sessions:

  • Getting Started: install, first graph, storage choices
  • AI agents: hand a graph to an LLM agent: describe() prompts, semantic search, MCP

Everything else is linked where it comes up, and the Documentation section at the bottom indexes all five tracks.

What makes it different

Three things the graph does that you would otherwise build yourself.

From the project's README.

Comments (0)

Sign in to join the conversation.

No comments yet.