fix(rag): close audit gaps in the in-house engine

An adversarial audit of the piragi -> in-house swap surfaced nine confirmed
issues; this fixes all of them.

- Re-ingest now REPLACES a source's chunks instead of appending. Add
  VectorStore.delete_by_source and BaseIndexPlugin.replace_on_reingest (default
  True), called before add_chunks in both ingest paths. Without it every
  startup / periodic / manual reindex appended a fresh copy of each doc's
  chunks, growing the tables unbounded and crowding out distinct results.
  Conversations opt OUT (replace_on_reingest=False): their many messages share
  one source URI, so delete-by-source would wipe history.
- index_* now honor the plugin IngestResult. The explicit record endpoints
  (error / standard / decision / review / learning) raise on failure instead of
  writing a green tracking row for content that never persisted;
  conversation / journal indexing stays best-effort but skips the tracking row
  when the embed fails. index_message / index_entry return IngestResult.
- A deprecated index type (code) now returns 404 instead of a 500 leaked from
  _get_plugin's missing-plugin error: add OptimalService.is_index_registered
  and guard the stats / clear / refresh routes. The panel drops the dead 'Code'
  category, filter, badge, label, and mock data.
- Panel: getContext reads 'results' (matches SearchResponse) instead of a
  non-existent 'context' field; the reindex toast no longer reports phantom
  '0 code files'; the stats 'Updated' label uses the max timestamp across
  indexes rather than indexes[0]; ProactiveContextItem matches the wire shape.
- Drop the always-zero per-document chunk_count from the documents API.
- Remove dead RAG settings (hybrid_search, cross_encoder) the engine never
  consumed, and correct stale piragi / BM25 references in code, README, and
  CLAUDE.md. Delete the unused duplicate roboco/kb embedder package the swap
  shipped.

Adds tests for replace-on-reingest (incl. the conversations carve-out) and the
deprecated-index 404.
This commit is contained in:
Renn F
2026-06-15 04:55:16 +02:00
parent e53eb5b7ee
commit 6422f77bb9
24 changed files with 251 additions and 1134 deletions
+4 -12
View File
@@ -53,13 +53,6 @@ import { isMockMode } from "@/lib/mock-data";
// =============================================================================
const mockSearchResults: KBSearchResult[] = [
{
content: "The TaskService handles all task lifecycle operations including creation, assignment, status transitions, and completion tracking...",
source: "roboco/services/tasks.py",
score: 0.92,
index_type: KBIndexType.CODE,
metadata: { language: "python", lines: "45-120" },
},
{
content: "## Task Lifecycle\n\nTasks follow a strict state machine from PENDING through IN_PROGRESS to COMPLETED. Each transition requires specific conditions...",
source: "docs/architecture/task-lifecycle.md",
@@ -85,7 +78,6 @@ const mockSearchResults: KBSearchResult[] = [
const mockStats: KBStats = {
indexes: [
{ index_type: KBIndexType.CODE, document_count: 1250, chunk_count: 8500, last_updated: "2024-01-15T12:00:00Z" },
{ index_type: KBIndexType.DOCUMENTATION, document_count: 45, chunk_count: 320, last_updated: "2024-01-15T11:30:00Z" },
{ index_type: KBIndexType.CONVERSATIONS, document_count: 890, chunk_count: 4200, last_updated: "2024-01-15T12:15:00Z" },
{ index_type: KBIndexType.JOURNALS, document_count: 156, chunk_count: 780, last_updated: "2024-01-15T10:00:00Z" },
@@ -95,8 +87,8 @@ const mockStats: KBStats = {
{ index_type: KBIndexType.REVIEWS, document_count: 234, chunk_count: 1170, last_updated: "2024-01-15T10:00:00Z" },
{ index_type: KBIndexType.LEARNINGS, document_count: 89, chunk_count: 445, last_updated: "2024-01-15T10:00:00Z" },
],
total_documents: 2799,
total_chunks: 15245,
total_documents: 1549,
total_chunks: 6745,
};
// Backend returns stats as dict, we need to transform to array
@@ -202,8 +194,8 @@ async function getContext(params: RAGQueryRequest): Promise<KBSearchResult[]> {
top_k: params.max_context_chunks ?? 5,
};
const response = await api.post<{ context: KBSearchResult[] }>("/optimal/rag/context", backendParams);
return response.data.context;
const response = await api.post<KBSearchResponse>("/optimal/rag/context", backendParams);
return response.data.results;
}
// =============================================================================