Implementation:23blocks OS Ai maestro Index Delta
| Knowledge Sources | |
|---|---|
| Domains | Memory, Indexing |
| Last Updated | 2026-10-26 10:00 GMT |
Overview
Concrete tool for delta-indexing agent conversation transcripts into CozoDB, provided by AI Maestro's `lib/index-delta.ts` and `lib/rag/ingest.ts`.
Description
The runIndexDelta function is the entry point for the subconscious indexing loop. It discovers new conversation transcripts, parses JSONL lines, generates embeddings, and writes them to the per-agent CozoDB. It uses a pinned database connection (to survive LRU evictions during large indexes) and a concurrency throttle.
indexConversationDelta does the actual batch ingestion: it reads a conversation JSONL file starting from the last-indexed message count, parses each line with parseConversationLine, generates embeddings via embedTexts, and records the conversation in CozoDB via recordConversation.
acquireIndexSlot is a mutex that prevents concurrent indexing of the same agent (max concurrent indexes bounded globally).
Usage
- Call `runIndexDelta` from the subconscious maintenance loop or the index-delta API route.
- `indexConversationDelta`, `parseConversationLine`, and `acquireIndexSlot` are internal — accessed via `runIndexDelta`.
Code Reference
Source Location
- Repository: ai-maestro
- File: lib/index-delta.ts (L38-55 acquireIndexSlot, L599-606 runIndexDelta), lib/rag/ingest.ts (L92-98 parseConversationLine, L313-322 indexConversationDelta), lib/cozo-schema-simple.ts (L220 recordConversation)
Signature
export async function runIndexDelta(
agentId: string,
options: { dryRun?: boolean; batchSize?: number } = {}
): Promise<IndexDeltaResult>
export async function indexConversationDelta(
agentDb: AgentDatabase,
conversationFile: string,
lastIndexedMessageCount: number,
options: { batchSize?: number }
): Promise<IngestionStats>
export function parseConversationLine(line: string): ConversationMessage[]
async function acquireIndexSlot(agentId: string): Promise<() => void>
export async function recordConversation(
agentDb: AgentDatabase,
conversation: { agentId: string; sessionId: string; [key: string]: any }
): Promise<void>
interface IndexDeltaResult {
success: boolean
agent_id: string
new_conversations_discovered: number
total_messages_processed: number
error?: string
}
interface IngestionStats {
totalMessages: number
processedMessages: number
skippedMessages: number
embeddingsGenerated: number
termsExtracted: number
}
Import
import { runIndexDelta } from '@/lib/index-delta'
import { indexConversationDelta, parseConversationLine } from '@/lib/rag/ingest'
import { recordConversation } from '@/lib/cozo-schema-simple'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| agentId | string | Yes | Agent UUID to index |
| options.dryRun | boolean | No | Preview only (no writes) |
| options.batchSize | number | No | Messages per batch (default 2) |
| conversationFile | string | Yes (delta) | JSONL transcript path |
| lastIndexedMessageCount | number | Yes (delta) | Delta offset |
Outputs
| Name | Type | Description |
|---|---|---|
| runIndexDelta() returns | Promise<IndexDeltaResult> | Success, conversations discovered, messages processed |
| indexConversationDelta() returns | Promise<IngestionStats> | Messages processed, embeddings generated |
| acquireIndexSlot() returns | Promise<() => void> | Release function (prevents concurrent indexing) |
Usage Examples
import { runIndexDelta } from '@/lib/index-delta'
// Index new conversation content for an agent
const result = await runIndexDelta('agent-uuid', { batchSize: 5 })
console.log(`Indexed ${result.total_messages_processed} new messages`)
console.log(`Discovered ${result.new_conversations_discovered} new conversations`)
Related Pages
Implements Principle
- Principle:23blocks_OS_Ai_maestro_Conversation_Delta_Indexing
- Principle:23blocks_OS_Ai_maestro_Memory_Consolidation