LatticeDB: An Embedded Single-File Graph Database with Vector and Full-Text Search
LatticeDB is an embedded, single-file property-graph database designed for relationship-heavy workloads on a single machine. It integrates graph traversal, HNSW vector similarity search, and BM25 full-text search into a single query engine, eliminating the need for separate databases for semantic, textual, and relational data.
Unified Query Layer for Graph, Vector, and Text
LatticeDB allows developers to query data by relationship, semantics, and text within a single query language. This unification is particularly useful for Graph RAG and agent memory systems where a query might need to find a semantic match, traverse to a related entity, and filter by specific text.
Cypher Query Language Support
LatticeDB implements a subset of the Cypher query language, supporting key operations including:
- Traversal:
MATCH,WHERE,RETURN, and variable-length paths (e.g.,*1..3). - Modification:
CREATE,DELETE,SET,REMOVE, andMERGE. - Search Operators: The
<=>operator for vector distance and the@@operator for full-text search. - Data Handling:
WITH,UNWIND, and aggregations such ascount,sum,avg,min,max, andcollect.
Integrated Search Capabilities
- Vector Search: Uses Hierarchical Navigable Small World (HNSW) approximate nearest neighbor search with configurable
Mandefparameters. It supports built-in hash embeddings and provides an HTTP client for Ollama and OpenAI. - Full-Text Search: Employs a BM25-ranked inverted index with tokenization, stemming, and fuzzy search via configurable Levenshtein distance.
Performance Benchmarks
LatticeDB is written in Zig and optimized for low-latency local operations. Benchmarks conducted on an Apple M1 (single-threaded) demonstrate the following performance characteristics:
Core Operation Latency
| Operation | Latency | Throughput |
|---|---|---|
| Node lookup | 0.13 µs | 7.9M ops/sec |
| Node creation | 0.65 µs | 1.5M ops/sec |
| Edge traversal | 9 µs | 111K ops/sec |
| Full-text search (100 docs) | 19 µs | 53K ops/sec |
| 10-NN vector search (1M vectors) | 0.83 ms | 1.2K ops/sec |
Vector Search Scaling
At a scale of 1 million vectors (128-dimensional cosine vectors), LatticeDB achieves a mean latency of 0.83 ms with 100% recall@10. Search latency scales sub-linearly (O(log N)).
Graph Traversal vs. SQLite
LatticeDB significantly outperforms SQLite's recursive CTEs for graph traversals. In a social network graph with 100K nodes and 500K edges, a 2-hop traversal takes 38.7 µs in LatticeDB compared to 548.3 µs in SQLite (a 14x speedup). For deeper traversals (depth 50), the speedup reaches 2,819x.
Architecture and Operational Model
LatticeDB follows a "local-first" philosophy, mirroring the operational simplicity of SQLite.
Storage: The entire database is stored in a single portable file.
Concurrency: It uses an embedded single-writer model. One process owns the file, making it unsuitable for multi-application concurrent writes.
Durability: It utilizes a write-ahead log (WAL) for crash recovery and ACID transactions with commit/rollback capabilities.
Event Streaming: The engine includes durable named streams and a built-in graph changefeed that share the same transaction/WAL path as graph writes.
Bindings: While the core is written in Zig, LatticeDB provides official bindings for Python, TypeScript/Node.js, and Go.
Use Case Analysis
Ideal Use Cases
- Local Knowledge Tools: Applications requiring graph structures without the overhead of a separate server.
- Agent Memory and RAG: Pipelines that combine semantic search with relationship traversal.
- Connected Local Data: Managing citation graphs, entity graphs, or personal notes.
- Local Development: Prototyping for Neo4j or Weaviate on a single machine.
When to Avoid LatticeDB
- Multi-Writer Requirements: If multiple applications must write to the same database simultaneously, a client-server database like PostgreSQL or Neo4j is required.
- Tabular Data: For data that fits naturally into rows and columns (e.g., sales records), relational databases remain more efficient.
- Distributed Scaling: LatticeDB is limited to a single machine; it does not support sharding or replication across clusters.
- Full Cypher Compliance: It does not yet support
OPTIONAL MATCHorCALLprocedures.
Community Insights
Users on Hacker News have noted the project's impressive performance and the utility of the "when not to use" documentation. However, some discrepancies in benchmark results have been reported. One user (@adsharma) reported different results on an M4 Mac Mini, noting that while LatticeDB still outperformed SQLite in traversals, the speedup factor was lower than the official benchmarks (e.g., 2.8x for 1-hop traversal instead of 36x).
Other community discussions highlighted potential alternatives and comparisons to other emerging "local-first" graph tools such as LadybugDB, SparrowDB, and DuckPGQ.
Sources
Related
- Project
- Project
- Project
- Project
- Project