Embedded property-graph database with native vector and full-text indexing.

One file. Relationship traversal, vector similarity, BM25 full-text search, durable streams, and ACID transactions in one local engine and one query layer.

Think SQLite, but for connected data you want to query by relationship, semantics, and text.

curl -fsSL https://raw.githubusercontent.com/jeffhajewski/latticedb/main/dist/install.sh | bash pip install latticedb npm install @hajewski/latticedb

One query. Three search modes.

Vector similarity, full-text search, and graph traversal in a single Cypher query.

-- Find chunks similar to a query, traverse to their document, then to the author
MATCH (chunk:Chunk)-[:PART_OF]->(doc:Document)-[:AUTHORED_BY]->(author:Person)
WHERE chunk.embedding <=> $query_vector < 0.3
  AND doc.content @@ "neural networks"
RETURN doc.title, chunk.text, author.name
ORDER BY chunk.embedding <=> $query_vector
LIMIT 10

Built for speed

0.22 µs
Property read by node id
8.8 µs
2-hop Cypher traversal @ 100K nodes
122 µs
10-NN vector search @ 100K, 98% recall
44 µs
Durable commit, fsynced

Medians for 0.17.0, measured through the public C API with the default settings on an Apple M5. Method, spreads and full tables.

How it compares

LatticeDB and SQLite, same machine, same durability

OperationLatticeDBSQLite
One-row durable commit44 µs42 µs
Inserts, 1,000 per transaction332K nodes/s1.84M rows/s
Lookup by an indexed property, 100K rows2.3 µs3.0 µs
2-hop count, 100K nodes8.8 µs8.9 µs
3-hop count, 100K nodes21 µs29 µs
Paths of 1 to 5 hops, 100K nodes600 µs1,361 µs

Medians, each database through its own C API: LatticeDB 0.17.0 with its defaults, SQLite 3.51.0 with WAL and synchronous=FULL, joins on indexed columns and a recursive CTE for the last row. SQLite is level on short traversals and several times faster at bulk inserts; LatticeDB is about twice as fast on long paths. How it was measured. Other systems' published figures are cited in the docs, apart from these measurements, with an honest account of what each alternative does better:

Everything in one library

Graph

  • Stable edge IDs for traversal and property updates
  • Large node and edge properties via B+Tree overflow storage
  • Multi-hop traversal with validated variable-length patterns
  • MERGE, WITH, UNWIND, expression LIMIT/SKIP, aggregations

Vector Search

  • HNSW approximate nearest neighbor
  • ef_search tunable per query
  • 98% recall@10 at 100K vectors with the defaults
  • Built-in hash embeddings or Ollama/OpenAI

Full-Text Search

  • BM25-ranked inverted index
  • Tokenization and English stop words
  • Fuzzy search with Levenshtein distance

Streams and Changefeeds

  • Durable named streams stored in system B+Trees
  • Per-stream sequences and explicit consumer offsets
  • Manual trim for retention control
  • Built-in graph changefeed with large-value summaries

Backup and Restore

  • Copy a database without closing it
  • Ship changes continuously to a directory or a mounted volume
  • Restore to a point in time, not just to the last snapshot
  • Restoring replays through the same recovery path as a crash

Portable Databases

  • Serialize a whole database to bytes and open one from bytes
  • A database per case or tenant, kept in object storage
  • Open :memory: and never touch the disk
  • Cheap because a database is one file, so serializing is reading it

Safe by Default

  • One process at a time, enforced with a lock on the file
  • A second writer is refused rather than left to corrupt the data
  • The write-ahead log is checkpointed as it grows, not only on close
  • Every write goes through the log, including plain Cypher

What's new in 0.18.1

A null removes a property on every write path, and vector calls say when there is no index.

Null Properties

  • SET n += {x: null} removes x, as Cypher specifies
  • CREATE and SET n = {...} leave a null out
  • Setting a property to null through the API removes it
  • JSON and CSV import leave null properties out

Vector Errors

  • Without a vector index, vector calls fail as unsupported, not as an I/O error
  • The message says the database has no vector index
  • A refused batch insert leaves no node behind
  • A Cypher <=> search there says the same

Compatibility

  • No change to the file or the log format
  • Nulls an earlier version stored read back until removed
  • A relationship MERGE on a null property now fails
  • The C API keeps every signature

0.18.1 is a patch on 0.18.0, which added reading, removing and Cypher-setting a node's vector. Read the 0.18.1 release notes

From Sample Code to Graph

This graph is rendered from the exact creation/query pattern shown below.

Construct and Query

These statements build the graph shown below.

CREATE (alice:Person {name: "Alice"})
CREATE (doc:Document {title: "Attention Is All You Need"})
CREATE (c1:Chunk {text: "Self-attention..."})
CREATE (c2:Chunk {text: "Transformer blocks..."})

CREATE (c1)-[:PART_OF]->(doc)
CREATE (c2)-[:PART_OF]->(doc)
CREATE (doc)-[:AUTHORED_BY]->(alice)

MATCH (chunk:Chunk)-[:PART_OF]->(doc:Document)-[:AUTHORED_BY]->(author:Person)
RETURN doc.title, chunk.text, author.name;
Knowledge graph visualization with Chunk, Document, and Person nodes connected by PART_OF and AUTHORED_BY relationships.
Rendered from the snippet above. Download DOT source.

Get started in 30 seconds

Python

pip install latticedb
from latticedb import Database
from latticedb.embedding import hash_embed

with Database("knowledge.db", create=True, enable_vectors=True, vector_dimensions=128) as db:
    with db.write() as txn:
        alice = txn.create_node(labels=["Person"], properties={"name": "Alice"})
        doc = txn.create_node(labels=["Document"], properties={"title": "Attention Is All You Need"})
        chunk = txn.create_node(labels=["Chunk"], properties={"text": "Self-attention..."})

        txn.set_vector(chunk.id, "embedding", hash_embed("transformer", dimensions=128))
        txn.create_edge(chunk.id, doc.id, "PART_OF")
        txn.create_edge(doc.id, alice.id, "AUTHORED_BY")
        txn.commit()

    results = db.query("""
        MATCH (chunk:Chunk)-[:PART_OF]->(doc:Document)-[:AUTHORED_BY]->(author:Person)
        WHERE chunk.embedding <=> $query < 0.5
        RETURN doc.title, chunk.text, author.name
        ORDER BY chunk.embedding <=> $query
        LIMIT 5
    """, parameters={"query": hash_embed("attention mechanism", dimensions=128)})

    for row in results:
        print(f"{row['doc.title']} by {row['author.name']}")

TypeScript

npm install @hajewski/latticedb
import { Database } from "@hajewski/latticedb";
import { hashEmbed } from "@hajewski/latticedb/embedding";

const db = new Database("knowledge.db", {
  create: true, enableVectors: true, vectorDimensions: 128,
});
await db.open();

await db.write(async (txn) => {
  const alice = await txn.createNode({ labels: ["Person"], properties: { name: "Alice" } });
  const doc = await txn.createNode({ labels: ["Document"], properties: { title: "Attention Is All You Need" } });
  const chunk = await txn.createNode({ labels: ["Chunk"], properties: { text: "Self-attention..." } });

  await txn.setVector(chunk.id, "embedding", hashEmbed("transformer", 128));
  await txn.createEdge(chunk.id, doc.id, "PART_OF");
  await txn.createEdge(doc.id, alice.id, "AUTHORED_BY");
});

const results = await db.query(
  `MATCH (chunk:Chunk)-[:PART_OF]->(doc:Document)-[:AUTHORED_BY]->(author:Person)
   WHERE chunk.embedding <=> $query < 0.5
   RETURN doc.title, chunk.text, author.name
   ORDER BY chunk.embedding <=> $query
   LIMIT 5`,
  { query: hashEmbed("attention mechanism", 128) }
);

for (const row of results.rows) {
  console.log(`${row["doc.title"]} by ${row["author.name"]}`);
}

await db.close();