Inside Omnigraph: Lakehouse Graph Engine with Git-Style Branching for Fleets of AI Agents Khám Phá Omnigraph: Lakehouse Graph Engine Với Nhánh Rẽ Git Dành Cho Đội Ngũ Tác Tử AI
An architectural deep dive into Omnigraph—a Rust-powered graph database on object storage featuring Lance columnar layout, single-door manifest CAS commits, 3-way graph merging, and multimodal RRF retrieval. Phân tích sâu kiến trúc kỹ thuật của Omnigraph—hệ quản trị cơ sở dữ liệu đồ thị trên object storage viết bằng Rust với định dạng cột Lance, giao thức commit CAS một cửa, phân nhánh và hợp nhất đồ thị kiểu Git, cùng truy vấn đa phương thức RRF.
1. 🌐 The Coordination Crisis in Multi-Agent Knowledge Bases
When hundreds of autonomous coding agents or enterprise reasoning assistants operate concurrently against a shared knowledge graph, traditional database paradigms collapse under two opposing constraints:
- State Isolation vs. Knowledge Convergence: If agents write directly to a shared mutable graph, concurrent modifications trigger race conditions, inconsistent edge topologies, and poisoned retrieval contexts. Conversely, if each agent operates in an isolated silo, insights and verified artifacts cannot be pooled back into the organization’s central knowledge base.
- Infrastructure Cost & Operational Overhead: Traditional graph databases (e.g., Neo4j, TigerGraph) mandate stateful, memory-heavy server instances with attached persistent block storage. Scaling out to fleets of asynchronous agents requires expensive distributed coordination layers and separate secondary systems for vector indexing (Milvus, Pinecone) and full-text keyword retrieval (Elasticsearch).
flowchart LR
subgraph Traditional ["Legacy Architecture: Fragmented & Heavy"]
direction TB
A1[Agent Fleet] --> DB[(Stateful Graph DB\nNeo4j / RAM Heavy)]
A1 --> VEC[(Vector Index\nMilvus / Pinecone)]
A1 --> FTS[(Search Engine\nElasticsearch)]
DB -.-> Sync["Complex Distributed Sync & Lock Contention"]
end
subgraph OmnigraphArch ["Omnigraph: Lakehouse Native Graph"]
direction TB
B1[Agent Fleet on Isolated Branches] --> Engine[Omnigraph Engine\nRust + Arrow + DataFusion]
Engine --> Manifest["Single-Door Manifest CAS\n(__manifest journal)"]
Manifest --> Storage[("Object Storage\nS3 / MinIO / R2 / RustFS\nLance Columnar Datasets")]
end
To solve this, Omnigraph (ModernRelay/omnigraph) introduces a lakehouse-native graph database architecture built from the ground up in Rust. Running directly atop cloud object storage (AWS S3, Cloudflare R2, MinIO, or RustFS) and backed by the columnar Lance format, Omnigraph treats graphs like code repositories: providing isolated Git-style branches for individual agents, zero-copy pointer adoption, three-way topological graph merging, and fused multimodal retrieval in a single query engine.
2. 🏛️ Core Architectural Blueprint & Layers
Omnigraph decouples query planning, catalog validation, and graph transaction coordination from physical storage through an explicit multi-crate workspace:
flowchart TB
CLI[omnigraph CLI] --> CLUSTER[omnigraph-cluster]
CLI --> ENGINE[omnigraph Engine Core]
HTTP[omnigraph-server] --> ENGINE
HTTP --> POLICY[omnigraph-policy / Cedar]
CLUSTER --> STORAGE[omnigraph-storage]
CLUSTER --> ENGINE
ENGINE --> COMPILER[omnigraph-compiler\n.pg Schema & .gq AST]
ENGINE --> PLANNER[omnigraph-planner\nCost-Based Optimizer & Physical Plans]
ENGINE --> POLICY
ENGINE --> STORAGE
ENGINE --> LANCE[Lance Substrate\nArrow Columnar Datasets]
STORAGE --> OBJECTS[Object Storage: S3 / Azure Blob / MinIO / Local FS]
LANCE --> OBJECTS
Decoupled Subsystem Responsibilities
| Subsystem Crate | Core Engineering Responsibility | Implementation Invariants |
|---|---|---|
omnigraph-compiler | Parses .pg schemas and .gq queries, builds typed catalog representations, and lowers queries into intermediate representation (IR). | Zero Lance or storage dependency; strict type-safety and syntax validation. |
omnigraph-planner | Translates IR into logical and physical execution trees, evaluates cost models (e.g., BTREE vs. CSR graph traversal), and performs filter pushdown. | Cost decisions operate strictly over catalog statistics via PlanSource. |
omnigraph (engine) | Coordinates multi-dataset visibility, snapshots, mutation staging, graph branches, and three-way merging. | Enforces that physical dataset changes never mutate the accepted logical graph without a manifest commit. |
omnigraph-policy | Compiles declarative Cedar policy sets to gate every read, mutation, branch creation, or query invocation. | Enforces authorization server-side and engine-side via _as entry points. |
omnigraph-storage | Unified abstraction over S3-compatible APIs and local storage for manifests, cluster ledgers, locks, and recovery artifacts. | Provides CAS (Compare-And-Swap) object operations for optimistic concurrency. |
Lance Substrate | Low-level columnar Arrow v2.2 table layout, vector IVF-PQ/HNSW indexes, FTS tokenizers, and fragment versioning. | Upstream unmodified crates.io Lance v11.0.0; no custom forks or patched WAL layers. |
3. 🔒 The Single Publication Door: Manifest CAS Commit Protocol
In distributed databases running atop object storage, achieving atomic transactions across multiple discrete tables (node tables and edge tables) without a centralized lock manager is notoriously difficult. Naive implementations risk partial writes where node records are visible but edge relationships fail to land.
Omnigraph guarantees strict ACID transactional semantics across all graph tables via its Single Publication Door protocol (crates/omnigraph/src/db/manifest.rs and docs/dev/writes.md):
sequenceDiagram
autonumber
participant Agent as Agent / Mutation Pipeline
participant Staging as MutationStaging
participant Tables as Lance Table Datasets
participant Manifest as __manifest Journal (CAS)
participant Promotion as Linear HEAD Promotion
Agent->>Staging: Accumulate validated node/edge mutations
Staging->>Tables: Stage exact Lance transactions (detached commits)
Note over Tables: Writes new Lance data fragments & commits detached version<br/>Linear table HEAD remains unchanged
Staging->>Manifest: Conditional CAS write with all Table Pins & Lineage
alt CAS Succeeded
Manifest-->>Agent: Graph Commit Acknowledged (Atomic Visibility)
Agent-)Promotion: Asynchronously promote table HEADs to pinned versions
else CAS Precondition Conflict
Manifest-->>Agent: Err(Conflict) - Rollback staging
Note over Staging: Unreferenced detached versions stay invisible<br/>Reclaimed safely by background cleanup
end
The Invariants of Detached Table Commits
- Never Move Table HEAD Inline: When nodes or edges are inserted, Omnigraph writes immutable Lance fragments to object storage and generates a detached transaction UUID. The physical dataset’s linear
HEADis not moved. - Atomic Manifest Pinning: Every participant table’s staged version, target pin, and graph lineage entry are recorded into a single manifest row payload. A conditional write (
put_optswith CAS or etag verification) commits the manifest. - Crash Convergence Without Recovery Sidecars: If an agent node crashes prior to step 4, the detached Lance versions on object storage are completely invisible to readers—no other transaction or snapshot references them. No complex undo log or write-ahead-log rollback is required; background GC simply cleans orphan fragments.
4. 🌿 Git-Style 3-Way Graph Merging Across Agent Fleets
Just as human software engineers write features in isolated Git branches before opening pull requests, Omnigraph allows autonomous agents to fork dedicated graph branches:
# Agent initializes an isolated memory scratchpad branch
omnigraph branch create agent-research-task-42 --from main
When an agent finishes synthesizing research or processing documents, its changes are reconciled back into main via Omnigraph::branch_merge.
The 4 Table Merge Routes
For every node and edge table modified in the branch, Omnigraph’s classifier selects the most optimal route:
flowchart TD
Start["Examine Table Lifetimes\n(Base, Source Branch, Target Branch)"] --> CheckEq{"Target == Base?"}
CheckEq -- Yes --> Adopt["1. Pointer Adoption\nZero-copy ref pointer handoff\nInstantaneous metadata-only merge"]
CheckEq -- No --> CheckInsert{"Contiguous Insertion Proof\n(omnigraph.insert_absence = v1)?"}
CheckInsert -- Yes --> Replay["2. Proven Insertion Replay\nAppend certified immutable fragments\nSkip join & ID conflict preflight"]
CheckInsert -- No --> CheckLineage{"Lineage Candidate Budget\n(< 32 MiB)?"}
CheckLineage -- Yes --> Lineage["3. Lineage Candidate Scan\nBitmask diffing on pinned metadata"]
CheckLineage -- No --> Walk["4. 2-Phase Bounded Cursor Walk\nPhase 1: Sort narrow keys (id + rowaddr)\nPhase 2: Hydrate full rows in 64 MiB chunks"]
The 2-Phase Bounded Memory Cursor Walk
When concurrent edits modify identical entities, Omnigraph falls back to an ordered three-way cursor walk that guarantees strict bounded memory utilization regardless of dataset scale:
- Phase 1 (Key Sorting): Only narrow keys (
id,_rowid,_rowaddr) are streamed and sorted. Payload columns are strictly barred from theSortExecpipeline, limiting memory to a few dozen bytes per candidate row. - Phase 2 (Chunked Hydration): Sorted keys are hydrated into complete rows in bounded batches with a hard 64 MiB ceiling. If a chunk exceeds 64 MiB during hydration, the chunk is dropped and retried with half the row size, preventing Out-Of-Memory (OOM) failures even on memory-constrained nodes.
5. 🔍 Multimodal Context Assembly: Graph + Vector + BM25
Retrieval-Augmented Generation (RAG) fails when limited to semantic vector search alone (which hallucinates connections) or relational graph queries alone (which miss unstructured context). Omnigraph solves this with its native GQ (Graph Query) language, combining topological graph traversal, HNSW vector proximity, and BM25 full-text indexing with Reciprocal Rank Fusion (RRF):
// Example: Multi-Agent Context Assembly Query
query find_expert_context($query_vec: Vector(1536), $keyword: String) {
match {
$author: Person
$doc: Document
$author -[:AUTHORED]-> $doc
search($doc.title, $keyword)
}
return {
$author.name,
$doc.title,
$doc.summary
}
order {
// Fusing Vector KNN and BM25 Text Relevance into a single ranked stream
rrf(
nearest($doc.embedding, $query_vec),
bm25($doc.body, $keyword)
)
}
limit 10
}
Traversal Cost Optimizer: Indexed BTREE vs. In-Memory CSR
When resolving graph edge expansions (Expand), Omnigraph’s query engine switches dynamically between two physical execution modes:
- Indexed BTREE Mode: Used for small input frontiers (e.g.,
< 1,024entities). The engine evaluates point lookups directly against Lance scalar indexes without caching whole topology graphs. - CSR (Compressed Sparse Row) Mode: When queries expand across deep hops or wide frontiers, Omnigraph materializes and caches a memory-efficient CSR/CSC topology representation, avoiding thousands of sequential object storage lookups.
6. ⚔️ Architectural Comparison: Omnigraph vs. Traditional Solutions
| Technical Dimension | Neo4j / Traditional Graph | Vector Stores (Milvus/Pinecone) | Omnigraph Lakehouse |
|---|---|---|---|
| Storage Substrate | Stateful disk blocks / Memory page cache | Proprietary cluster / Cloud index | Open Lance format on generic S3/Blob storage |
| Branching & Isolation | None (Single global database instance) | Namespace tagging (No isolation or lineage) | First-class Git-style branches ({name}.{ULID}) |
| Commit Protocol | Distributed 2-Phase Commit / Raft | Asynchronous index replication | Single-Door Manifest CAS (Optimistic, lockless) |
| Merge Capabilities | Manual application ETL | N/A | Automated 3-way graph merge with zero-copy adoption |
| Query Modalities | Pure Cypher (Vector as bolted-on plugin) | Pure ANN Vector | Unified Graph Traversals + Vector + BM25 via RRF |
| Security Layer | Role-Based Access Control (RBAC) | API key tokens | Cedar Policy as Code enforced server & engine-side |
| Cold Compute Cost | High (idle nodes keep memory warm) | Moderate to High | Zero (stateless engine boots directly over S3) |
7. 🛠️ Actionable Engineering Takeaways
Studying Omnigraph’s architecture offers several valuable lessons for designing modern AI data systems:
- Leverage Columnar Object Storage for State, Not Just Warehousing: Using high-performance columnar formats like Lance allows systems to achieve analytical scan speeds and sub-millisecond point retrieval directly against object stores, eliminating the need for expensive dedicated disk volumes.
- Enforce Transaction Atomicity at the Manifest, Not the File Level: Writing data changes as detached, unreferenced objects before performing a single CAS on an authority manifest eliminates distributed locking protocols and guarantees painless crash recovery.
- Decouple Key Sorting from Data Hydration: In large-scale diffing or merging algorithms, sorting narrow tuple keys (
id,_rowaddr) before hydrating bloated payload columns prevents OOM errors and maximizes CPU L1/L2 cache locality. - Make Multi-Agent Workspaces Branchable by Default: When coordinating AI agents, do not rely on locks or synchronous queues. Giving each agent an isolated branch with automatic 3-way reconciliation unlocks massive parallel throughput while preserving system integrity.
1. 🌐 Khủng Hoảng Đồng Bộ Dữ Liệu Trong Đội Ngũ Tác Tử AI
Khi hàng trăm tác tử AI (autonomous coding agents hoặc reasoning assistants) cùng vận hành song song trên một cơ sở tri thức đồ thị chung, các mô hình cơ sở dữ liệu truyền thống thường gặp bế tắc trước hai rào cản kỹ thuật cốt lõi:
- Xung đột ghi và ô nhiễm ngữ cảnh: Nếu các agent cùng ghi trực tiếp vào một đồ thị biến đổi (mutable graph), xung đột dữ liệu (race conditions) và sự cố topo không nhất quán sẽ lập tức làm ô nhiễm bộ nhớ của toàn hệ thống. Ngược lại, nếu mỗi agent làm việc trong một cơ sở dữ liệu cô lập hoàn toàn, tri thức mới được tạo ra sẽ bị phân mảnh và không thể tổng hợp về trung tâm.
- Gánh nặng chi phí vận hành: Các cơ sở dữ liệu đồ thị truyền thống (như Neo4j, TigerGraph) đòi hỏi các server cấu hình RAM khủng, ổ cứng khối (block storage) liên tục hoạt động. Để phục vụ truy vấn đa dạng của agent, hệ thống còn phải tích hợp thêm Milvus/Pinecone cho vector và Elasticsearch cho tìm kiếm từ khóa, dẫn đến kiến trúc vô cùng cồng kềnh.
flowchart LR
subgraph Traditional ["Kiến Trúc Truyền Thống: Phân Mảnh & Nặng Nề"]
direction TB
A1[Đội Ngũ AI Agent] --> DB[(Database Đồ Thị\nNeo4j / Tốn RAM)]
A1 --> VEC[(Vector Index\nMilvus / Pinecone)]
A1 --> FTS[(Search Engine\nElasticsearch)]
DB -.-> Sync["Xung Đột Đồng Bộ & Tranh Chấp Khóa Phức Tạp"]
end
subgraph OmnigraphArch ["Omnigraph: Kiến Trúc Lakehouse Đồ Thị Chuẩn"]
direction TB
B1[Đội Ngũ Agent Trên Nhánh Cô Lập] --> Engine[Omnigraph Engine\nRust + Arrow + DataFusion]
Engine --> Manifest["Cửa Commit Duy Nhất CAS\n(Nhật ký __manifest)"]
Manifest --> Storage[("Object Storage\nS3 / MinIO / R2 / RustFS\nĐịnh Dạng Cột Lance")]
end
Để giải quyết triệt để bài toán này, Omnigraph (ModernRelay/omnigraph) mang đến một kiến trúc cơ sở dữ liệu đồ thị chuẩn lakehouse hoàn toàn mới được viết bằng Rust. Bằng cách vận hành trực tiếp trên object storage (AWS S3, Cloudflare R2, MinIO hoặc RustFS) thông qua định dạng cột Lance, Omnigraph quản lý đồ thị giống như một kho mã nguồn Git: hỗ trợ phân nhánh cô lập cho từng agent, tiếp quản con trỏ không sao chép dữ liệu (zero-copy), thuật toán hợp nhất đồ thị 3 chiều (3-way merge) và hợp nhất truy vấn đa phương thức trong một runtime duy nhất.
2. 🏛️ Kiến Trúc Hệ Thống & Các Lớp Phân Tách
Mã nguồn Omnigraph được chia nhỏ thành các crate độc lập trong workspace Cargo, đảm bảo ranh giới chịu trách nhiệm rõ ràng giữa trình biên dịch, tối ưu kế hoạch thực thi và lớp lưu trữ:
flowchart TB
CLI[omnigraph CLI] --> CLUSTER[omnigraph-cluster]
CLI --> ENGINE[omnigraph Engine Core]
HTTP[omnigraph-server] --> ENGINE
HTTP --> POLICY[omnigraph-policy / Cedar]
CLUSTER --> STORAGE[omnigraph-storage]
CLUSTER --> ENGINE
ENGINE --> COMPILER[omnigraph-compiler\nPhân Tích .pg Schema & .gq AST]
ENGINE --> PLANNER[omnigraph-planner\nTối Ưu Hóa Chi Phí & Kế Hoạch]
ENGINE --> POLICY
ENGINE --> STORAGE
ENGINE --> LANCE[Tầng Lance Substrate\nDataset Cột Apache Arrow]
STORAGE --> OBJECTS[Object Storage: S3 / Azure Blob / MinIO / Local FS]
LANCE --> OBJECTS
Chi Tiết Trách Nhiệm Các Module Cốt Lõi
| Crate Hệ Thống | Trách Nhiệm Kỹ Thuật Chính | Quy Tắc Bất Biến (Invariants) |
|---|---|---|
omnigraph-compiler | Phân tích cú pháp schema .pg và truy vấn .gq, xây dựng catalog có kiểu tĩnh và hạ cấp (lowering) xuống dạng biểu diễn trung gian (IR). | Hoàn toàn độc lập với Lance hay storage; bảo đảm tính toàn vẹn cú pháp và kiểu dữ liệu. |
omnigraph-planner | Chuyển đổi IR thành cây kế hoạch logic/vật lý, tính toán chi phí (chọn duyệt BTREE hay bảng CSR in-memory) và đẩy bộ lọc (filter pushdown). | Quyết định dựa trên thống kê thực tế lấy từ catalog thông qua PlanSource. |
omnigraph (engine) | Điều phối tầm nhìn đa bảng (multi-dataset visibility), snapshot, staging thao tác, quản lý nhánh rẽ và hợp nhất dữ liệu. | Đảm bảo các thay đổi vật lý của dataset không bao giờ được coi là hợp lệ nếu chưa commit qua manifest. |
omnigraph-policy | Biên dịch các bộ quy tắc bảo mật Cedar nhằm kiểm soát phân quyền cho mọi thao tác đọc, ghi, tạo nhánh hay gọi truy vấn. | Thực thi bảo mật cả ở tầng máy chủ HTTP và tầng nội tại engine thông qua các cổng _as. |
omnigraph-storage | Trừu tượng hóa truy cập object storage S3/Azure Blob/Local FS cho manifest, ledger cụm, khóa và báo cáo khôi phục. | Cung cấp các thao tác nguyên tử CAS (Compare-And-Swap) cho concurrency an toàn. |
Lance Substrate | Định dạng cột Arrow v2.2, chỉ mục vector IVF-PQ/HNSW, tokenizer full-text và quản lý các phân mảnh (fragments). | Sử dụng trực tiếp Lance v11.0.0 nguyên bản trên crates.io; không dùng bản vá fork hay hệ WAL riêng. |
3. 🔒 Giao Thức Commit CAS Qua Cửa Duy Nhất (Single Publication Door)
Trên nền tảng object storage, việc đảm bảo tính toàn vẹn ACID khi thay đổi đồng thời nhiều bảng (bảng nốt và bảng cạnh) mà không sử dụng lock server trung tâm là bài toán cực kỳ hóc búa. Các kiến trúc non nớt rất dễ rơi vào trạng thái nốt đã ghi thành công nhưng cạnh chưa kịp ghi, làm sai lệch topo đồ thị.
Omnigraph hiện thực hóa cơ chế toàn vẹn dữ liệu hoàn hảo bằng Giao thức commit qua cửa duy nhất (crates/omnigraph/src/db/manifest.rs và docs/dev/writes.md):
sequenceDiagram
autonumber
participant Agent as Agent / Thao Tác Ghi
participant Staging as MutationStaging
participant Tables as Lance Table Datasets
participant Manifest as Nhật Ký __manifest (CAS)
participant Promotion as Thăng Hạng Con Trỏ HEAD
Agent->>Staging: Tập hợp các mutation nốt/cạnh đã kiểm tra hợp lệ
Staging->>Tables: Stage các transaction Lance (detached commits)
Note over Tables: Ghi các fragment dữ liệu mới & tạo detached version<br/>Con trỏ HEAD tuyến tính của bảng không bị dịch chuyển
Staging->>Manifest: Ghi CAS có điều kiện kèm toàn bộ Pin bảng & Lineage
alt CAS Thành Công
Manifest-->>Agent: Xác nhận commit đồ thị (Tất cả bảng hiển thị đồng thời)
Agent-)Promotion: Bất đồng bộ thăng hạng HEAD của bảng lên version đã ghim
else CAS Bị Xung Đột Điều Kiện
Manifest-->>Agent: Err(Conflict) - Hủy bỏ staging
Note over Staging: Các version detached không có ai trỏ tới<br/>GC sẽ tự động dọn dẹp an toàn sau này
end
Các Đặc Điểm Bất Biến Của Detached Commits
- Không Di Chuyển HEAD Của Bảng Trước: Khi thêm nốt hoặc cạnh, Omnigraph chỉ ghi các file fragment bất biến lên object storage và tạo ra phiên bản độc lập (detached commit). Con trỏ
HEADcủa từng bảng hoàn toàn đứng yên. - Ghim Trạng Thái Đồng Khối Vào Manifest: Toàn bộ version của các bảng tham gia, transaction UUID và thông tin lịch sử nhánh đồ thị được gói gọn vào một dòng bản ghi duy nhất trong
__manifest. Một thao tác ghi nguyên tử CAS duy nhất quyết định sự thay đổi của cả đồ thị. - An Toàn Khi Sập Nguồn Mà Không Cần File Undo Log: Nếu máy chủ hoặc agent bị sập giữa chừng trước khi ghi manifest, các mảnh dữ liệu đã đẩy lên S3 hoàn toàn vô hình đối với mọi truy vấn vì không có manifest nào tham chiếu đến chúng. Không cần chạy các tiến trình rollback phức tạp; tác vụ dọn rác nền sẽ thu hồi các mảnh mồ côi này.
4. 🌿 Phân Nhánh & Hợp Nhất Đồ Thị 3 Chiều Kiểu Git
Tương tự như quy trình lập trình viên tạo nhánh Git để phát triển tính năng độc lập, Omnigraph cho phép mỗi tác tử AI tự tạo nhánh đồ thị riêng:
# Agent tạo nhánh làm việc độc lập từ main
omnigraph branch create agent-research-task-42 --from main
Khi agent hoàn thành nhiệm vụ, các thay đổi sẽ được hòa nhập vào nhánh main bằng hàm Omnigraph::branch_merge.
4 Tuyến Đường Hợp Nhất Bảng (Table Merge Routes)
Omnigraph tự động phân loại và áp dụng chiến lược hợp nhất tối ưu cho từng bảng dữ liệu:
flowchart TD
Start["So Sánh Vòng Đời Của Bảng\n(Base, Nhánh Nguồn, Nhánh Đích)"] --> CheckEq{"Đích == Base?"}
CheckEq -- Đúng --> Adopt["1. Pointer Adoption\nChuyển giao con trỏ (Zero-copy)\nHợp nhất metadata tức thì không tốn I/O"]
CheckEq -- Sai --> CheckInsert{"Bằng Chứng Ghi Chèn Contiguous\n(omnigraph.insert_absence = v1)?"}
CheckInsert -- Đúng --> Replay["2. Proven Insertion Replay\nGhép các fragment bất biến đã chứng thực\nBỏ qua phép join & kiểm tra xung đột ID"]
CheckInsert -- Sai --> CheckLineage{"Ngân Sách Ứng Viên Lineage\n(< 32 MiB)?"}
CheckLineage -- Đúng --> Lineage["3. Lineage Candidate Scan\nSo khớp bitmask trên metadata đã ghim"]
CheckLineage -- Sai --> Walk["4. Duyệt Con Trỏ 2 Pha Bounded Memory\nPha 1: Sắp xếp khóa hẹp (id + rowaddr)\nPha 2: Hydrate toàn bộ dòng trong khối 64 MiB"]
Thuật Toán Duyệt Con Trỏ Giới Hạn Bộ Nhớ (Bounded Memory Walk)
Khi cả hai nhánh cùng sửa đổi dữ liệu phức tạp, Omnigraph kích hoạt cơ chế hợp nhất con trỏ 2 pha giúp đảm bảo mức tiêu thụ RAM luôn trong tầm kiểm soát:
- Pha 1 (Key Sorting): Chỉ đọc và sắp xếp các cột khóa hẹp gồm
id,_rowid, và_rowaddr. Các cột dữ liệu nặng (payload/embedding) hoàn toàn bị loại khỏi toán tử sắp xếpSortExec, giảm tải bộ nhớ xuống chỉ còn vài chục byte trên mỗi dòng. - Pha 2 (Chunked Hydration): Sau khi đã xác định thứ tự và loại bỏ xung đột, engine mới tải đầy đủ dữ liệu theo từng khối nhỏ với giới hạn ngặt nghèo 64 MiB. Nếu dữ liệu thực tế vượt ngưỡng 64 MiB, khối đó sẽ bị hủy và chia đôi kích thước để thử lại, ngăn chặn tuyệt đối lỗi tràn bộ nhớ (OOM).
5. 🔍 Truy Vấn Đa Phương Thức: Đồ Thị + Vector + BM25
Các hệ thống RAG hiện nay thường gặp lỗi nghiêm trọng: tìm kiếm vector thuần túy thường sinh ảo giác vì thiếu ràng buộc logic, trong khi tìm kiếm quan hệ đồ thị thuần túy lại không thể khai thác ngữ nghĩa phi cấu trúc. Omnigraph giải quyết triệt để thông qua ngôn ngữ truy vấn GQ (Graph Query), cho phép kết hợp duyệt đồ thị, tìm kiếm vector HNSW và từ khóa BM25 thông qua thuật toán Reciprocal Rank Fusion (RRF):
// Ví dụ: Truy vấn lắp ráp ngữ cảnh chuyên gia cho Agent
query find_expert_context($query_vec: Vector(1536), $keyword: String) {
match {
$author: Person
$doc: Document
$author -[:AUTHORED]-> $doc
search($doc.title, $keyword)
}
return {
$author.name,
$doc.title,
$doc.summary
}
order {
// Hợp nhất điểm xếp hạng Vector KNN và điểm tần suất BM25
rrf(
nearest($doc.embedding, $query_vec),
bm25($doc.body, $keyword)
)
}
limit 10
}
Bộ Tối Ưu Chi Phí Duyệt Đồ Thị: BTREE Index vs. In-Memory CSR
Khi thực thi bước mở rộng quan hệ (Expand), bộ lập kế hoạch của Omnigraph đưa ra quyết định thông minh:
- Chế độ Indexed BTREE: Áp dụng khi tập biên đầu vào nhỏ (ví dụ
< 1.024thực thể). Engine thực hiện tra cứu trực tiếp trên chỉ mục BTREE của Lance mà không cần tải toàn bộ đồ thị vào RAM. - Chế độ CSR (Compressed Sparse Row): Khi truy vấn qua nhiều bước nhảy (multi-hop) hoặc số lượng thực thể lớn, engine tự động dựng cấu trúc mảng nén CSR/CSC trong bộ nhớ để duyệt cực nhanh, loại bỏ hàng ngàn request I/O dư thừa tới object storage.
6. ⚔️ Bảng So Sánh Kỹ Thuật: Omnigraph vs. Các Giải Pháp Truyền Thống
| Tiêu Chí Kỹ Thuật | Neo4j / Graph Truyền Thống | Cơ Sở Dữ Liệu Vector (Milvus/Pinecone) | Omnigraph Lakehouse |
|---|---|---|---|
| Hạ Tầng Lưu Trữ | Ổ cứng khối (Block Storage) / Tốn nhiều RAM | Cụm máy chủ chuyên dụng đắt đỏ | Lưu trữ trực tiếp trên S3/MinIO dạng cột Lance |
| Phân Nhánh & Cô Lập | Không hỗ trợ (Chỉ có 1 instance dữ liệu duy nhất) | Chỉ gắn tag namespace (Không có lineage) | Hỗ trợ nhánh rẽ kiểu Git hoàn chỉnh ({name}.{ULID}) |
| Giao Thức Ghi | Khóa 2 pha phân tán / Raft | Đồng bộ bất đồng bộ | Giao thức commit Manifest CAS một cửa (Lockless) |
| Khả Năng Merge | Phải viết script xử lý thủ công | Không áp dụng | Thuật toán 3-way merge tự động kèm zero-copy |
| Phương Thức Truy Vấn | Cypher thuần túy (Vector chỉ là tính năng phụ) | Chỉ có tìm kiếm vector gần đúng (ANN) | Đồ Thị + Vector KNN + BM25 hợp nhất qua RRF |
| Kiểm Soát Quyền | Phân quyền vai trò RBAC cơ bản | Quản lý qua API Key | Thực thi bộ luật Cedar Policy as Code từ tầng máy chủ đến lõi |
| Chi Phí Máy Chủ Chờ | Rất cao (Luôn phải duy trì server RAM lớn) | Trung bình đến Cao | Bằng 0 (Engine stateless có thể bật tắt linh hoạt trên S3) |
7. 🛠️ Bài Học Kỹ Thuật Đáng Giá
Từ thiết kế kiến trúc của Omnigraph, các kỹ sư phần mềm và kiến trúc sư hệ thống AI có thể rút ra 4 kinh nghiệm quý báu:
- Khai thác định dạng cột trên Object Storage cho dữ liệu tác vụ (Operational Data): Thay vì chỉ dùng S3 cho Data Lake lưu trữ thụ động, việc kết hợp định dạng cột tối ưu như Lance cho phép thực hiện cả truy vấn vector tốc độ cao lẫn tra cứu điểm dữ liệu với chi phí hạ tầng giảm tới 80%.
- Đảm bảo tính nguyên tử ở tầng Manifest thay vì khóa file vật lý: Thiết kế các thay đổi dữ liệu dưới dạng phiên bản độc lập (detached commits) và chỉ công bố quyền sở hữu thông qua một lệnh CAS duy nhất trên manifest giúp loại bỏ nhu cầu về cụm lock phân tán phức tạp và loại trừ nguy cơ hỏng dữ liệu khi sập nguồn.
- Tách biệt khóa định danh khỏi dữ liệu payload khi sắp xếp/hợp nhất: Trong các giải thuật xử lý diff hay merge dữ liệu lớn, việc chỉ sắp xếp các tuple khóa hẹp (
id,_rowaddr) rồi mới nạp dữ liệu nặng theo từng khối có chặn ngưỡng trần (bounded memory) là bí quyết cốt lõi để ngăn chặn lỗi Out-Of-Memory (OOM). - Chuẩn hóa mô hình phân nhánh cho các hệ thống Multi-Agent: Trong kỷ nguyên các tác tử AI tự chủ, đừng ép các agent phải tranh chấp ghi trên một luồng dữ liệu đơn lẻ. Hãy cung cấp cho chúng các nhánh rẽ dữ liệu cô lập và tự động giải quyết xung đột bằng thuật toán hợp nhất 3 chiều.