Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:23blocks OS Ai maestro Index Delta

From Leeroopedia
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

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment