Skip to content

RAG-3: Inject relevant Live doc chunks into system prompt #68

Description

@nonogv

Context

Depends on #67 (RAG-2). Part of the v2 RAG milestone.

What

Before building the system prompt, detect Live/device queries and inject the top relevant doc chunks.

Files: src/agent/chat.ts, src/server.ts

Logic:

  1. If isLiveOrProductionQuery(latestUserMessage) is true, call retrieveLiveDocs(query, 3)
  2. If chunks are returned, inject them into the system prompt as a fenced block:

```

Relevant Live documentation

Title
body text…

Title
body text…
```

Constraints:

  • Total injected context ≤ 1000 tokens (truncate body if needed, never truncate mid-sentence)
  • Only inject for learning/question requests — skip for pure action commands ("set tempo to 120")
  • retrieveLiveDocs must run with a 50ms timeout; on timeout or error, silently continue without injection — never delay the agent turn

Tests in src/agent/chat.test.ts:

  • System prompt includes doc chunks when retrieveLiveDocs returns results for a Live query
  • System prompt is unchanged when retrieveLiveDocs returns []
  • System prompt is unchanged for pure action commands even if isLiveOrProductionQuery is true

Acceptance criteria

  • Asking "how does Operator's FM ratio work?" injects the Operator manual section
  • Asking "set tempo to 120" does not inject anything
  • A retrieveLiveDocs timeout never adds latency to the agent response
  • Injected context stays under 1000 tokens

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestv2v2 power features

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions