aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / cortex-rs / README.md
| 1 | <p align="center"> |
| 2 | <img src="assets/avatar.jpg" width="140" height="140" alt="AIEN Sovereign Intelligence" style="border-radius: 50%; border: 2px solid #f59e0b;"> |
| 3 | </p> |
| 4 | |
| 5 | # cortex-rs |
| 6 | |
| 7 | [](https://github.com/aien-dev/cortex-rs/actions/workflows/ci.yml) |
| 8 | [](LICENSE) |
| 9 | [](SECURITY.md) |
| 10 | [](CONTRIBUTING.md) |
| 11 | [](https://drakestapleton.com) |
| 12 | |
| 13 | Native Rust memory engine with SQLite FTS5 lexical recall, bi-encoder vector similarity, and hardware-secured loopback isolation. |
| 14 | |
| 15 | ## Overview |
| 16 | |
| 17 | `cortex-rs` is the Linux-hosted memory service (native Rust, Axum) that Atlas and the AIEN agent tools call for lexical and semantic recall. It is not the canonical memory owner: under [ADR 0022](https://github.com/aien-dev/aien-architecture-mv/blob/main/docs/adr/0022-canonical-cortex-owner.md) the canonical Cortex owner at the Omega layer is omega `rx_cortex`, and under [ADR 0036](https://github.com/aien-dev/aien-architecture-mv/blob/main/docs/adr/0036-release-v1-memory-owner.md) the memory the v1 release tests is `aien-allen-memory` attached to an engaged ALLEN identity. |
| 18 | |
| 19 | It provides hybrid search combining BM25 full-text indexing with ONNX vector embeddings, enabling autonomous agents to recall procedures, lessons, and architectural discoveries across thousands of turns without context collapse. |
| 20 | |
| 21 | ## Features |
| 22 | |
| 23 | - **Sub-Millisecond Retrieval**: Pure compiled Rust using SQLite WAL mode and FTS5 inverted indexes with typical latency <1ms. |
| 24 | - **Hybrid Semantic Recall**: Direct integration with local bi-encoder vector servers for cosine similarity and dense embedding scoring. |
| 25 | - **Hardware Vault Security**: Zero plaintext secrets. All authentication uses bearer token validation bound to loopback interfaces (`127.0.0.1`). |
| 26 | - **Graph & Provenance Traversal**: Bidirectional relationship edges (`cortex_claims`, `cortex_entities`) for deep contextual graph traversal. |
| 27 | - **Unslop Standard**: Enforces clean technical facts without AI filler or speculative abstractions. |
| 28 | |
| 29 | ## Turnkey Reproduction & Benchmarks |
| 30 | |
| 31 | Run the engine and observe live latency and throughput metrics directly with a single command. |
| 32 | |
| 33 | ### 1. One-Line Docker Benchmark |
| 34 | |
| 35 | Execute the compiled native benchmark inside a container to evaluate SQLite WAL ingestion, FTS5 lexical retrieval, and graph claim traversal: |
| 36 | |
| 37 | ```bash |
| 38 | docker run --rm ghcr.io/aien-dev/cortex-rs:latest --bench |
| 39 | ``` |
| 40 | |
| 41 | Or build and run locally with Docker: |
| 42 | |
| 43 | ```bash |
| 44 | docker build -t cortex-rs https://github.com/aien-dev/cortex-rs.git |
| 45 | docker run --rm cortex-rs --bench |
| 46 | ``` |
| 47 | |
| 48 | Verified benchmark output on Grace Blackwell GB10: |
| 49 | |
| 50 | ```text |
| 51 | ================================================================================ |
| 52 | CORTEX-RS FLAGSHIP REPRODUCTION BENCHMARK |
| 53 | Target: SQLite WAL + FTS5 Inverted Index + Graph Claim Traversal |
| 54 | Records to ingest: 500 |
| 55 | ================================================================================ |
| 56 | |
| 57 | [1/3] Benchmarking Entity Ingestion (FTS5 + SQLite WAL)... |
| 58 | [2/3] Benchmarking FTS5 Lexical Search across 500 records... |
| 59 | [3/3] Benchmarking Bidirectional Graph Claim Traversal... |
| 60 | |
| 61 | ================================================================================ |
| 62 | BENCHMARK RESULTS SUMMARY (Reproducible Single-Command Output) |
| 63 | ================================================================================ |
| 64 | Corpus Size: 500 entities |
| 65 | Total Search Queries Run: 500 |
| 66 | -------------------------------------------------------------------------------- |
| 67 | METRIC p50 (µs) p95 (µs) p99 (µs) Rate / QPS |
| 68 | -------------------------------------------------------------------------------- |
| 69 | Entity Ingestion (WAL+FTS5) 76.9 145.6 8121.9 4375.6 writes/s |
| 70 | FTS5 Lexical Search 121.8 452.9 461.3 6341.2 qps |
| 71 | Graph Claim Traversal 7.3 7.5 10.2 133247.2 qps |
| 72 | -------------------------------------------------------------------------------- |
| 73 | Search p50 in milliseconds: 0.122 ms |
| 74 | Search p99 in milliseconds: 0.461 ms |
| 75 | ================================================================================ |
| 76 | ``` |
| 77 | |
| 78 | ### 2. Standalone Native Reproduction (Zero Docker) |
| 79 | |
| 80 | To run natively on Linux or macOS without Docker: |
| 81 | |
| 82 | ```bash |
| 83 | # Clone repository and execute the automated verification runner |
| 84 | git clone https://github.com/aien-dev/cortex-rs.git |
| 85 | cd cortex-rs |
| 86 | ./scripts/reproduce.sh |
| 87 | ``` |
| 88 | |
| 89 | Or run the built-in benchmark directly with Cargo: |
| 90 | |
| 91 | ```bash |
| 92 | cargo run --release -- --bench --bench-records 1000 |
| 93 | ``` |
| 94 | |
| 95 | ### 3. Running the Production Server |
| 96 | |
| 97 | #### Local Process |
| 98 | |
| 99 | ```bash |
| 100 | # Compile release binary |
| 101 | cargo build --release |
| 102 | |
| 103 | # Run Cortex-RS on local loopback |
| 104 | ./target/release/cortex-rs --port 18080 --db-path ~/.config/cortex/cortex.db |
| 105 | ``` |
| 106 | |
| 107 | #### Docker Container |
| 108 | |
| 109 | ```bash |
| 110 | docker run -d \ |
| 111 | --name cortex-rs \ |
| 112 | -p 18080:18080 \ |
| 113 | -e CORTEX_TOKEN=your-vault-token \ |
| 114 | ghcr.io/aien-dev/cortex-rs:latest |
| 115 | ``` |
| 116 | |
| 117 | ### 4. API Endpoints |
| 118 | |
| 119 | #### Health Check (Unauthenticated) |
| 120 | |
| 121 | ```bash |
| 122 | curl http://127.0.0.1:18080/health |
| 123 | # {"runtime":"native-arm64-rust","service":"cortex-rs","space":"atlas-memory","status":"ok","version":"0.1.0"} |
| 124 | ``` |
| 125 | |
| 126 | #### Entity Ingestion |
| 127 | |
| 128 | ```bash |
| 129 | curl -X POST http://127.0.0.1:18080/api/cortex/write \ |
| 130 | -H "Authorization: Bearer <TOKEN>" \ |
| 131 | -H "Content-Type: application/json" \ |
| 132 | -d '{ |
| 133 | "kind": "entity", |
| 134 | "value": { |
| 135 | "space": "atlas-memory", |
| 136 | "canonicalName": "system_module_1", |
| 137 | "entityType": "discovery", |
| 138 | "content": "Grace Blackwell GB10 unified memory architecture verification." |
| 139 | } |
| 140 | }' |
| 141 | ``` |
| 142 | |
| 143 | #### Lexical Search |
| 144 | |
| 145 | ```bash |
| 146 | curl -G http://127.0.0.1:18080/api/cortex/search \ |
| 147 | --data-urlencode "q=unified memory" \ |
| 148 | -H "Authorization: Bearer <TOKEN>" |
| 149 | ``` |
| 150 | |
| 151 | ## License |
| 152 | |
| 153 | This repository is licensed under the **Apache License, Version 2.0 (with LLVM Exception)**. |
| 154 | |
| 155 | See [LICENSE](../../LICENSE) for the full legal text. |