Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@four-bytes/four-opencode-brain",
"version": "1.8.1",
"version": "1.8.4",
"description": "Unified brain plugin — single SQLite DB for RAG search, memory, and knowledge base",
"license": "Apache-2.0",
"type": "module",
Expand Down
69 changes: 62 additions & 7 deletions src/search/unified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,68 @@ async function searchVec0(
)
.all(queryBlob, maxResults);

return rows.map((row) => ({
id: row.chunk_id,
title: `vec0:${row.chunk_id.slice(0, 8)}`,
excerpt: `[vec0 chunk] distance=${row.distance.toFixed(4)}`,
score: Math.max(0, 1 - row.distance),
content_type: "chunk" as const,
}));
if (rows.length === 0) return [];

// Batch-lookup real content from chunks table for all vec0 results
const MAX_BATCH_IDS = 500; // SQLite host-parameter safety ceiling
const chunkIds = rows.slice(0, MAX_BATCH_IDS).map((r) => r.chunk_id);
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
const placeholders = chunkIds.map(() => "?").join(",");
const chunkRows = db
.query(
`SELECT c.id, c.content, c.symbol, c.chunk_type, c.start_line, c.end_line,
c.chunk_index, c.kind, d.path AS source_path, d.title AS doc_title
FROM chunks c
JOIN documents d ON d.id = c.document_id
WHERE c.id IN (${placeholders})`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Vec0 content lookup still ignores search filters. Apply mergedFilters to the vec0 chunk resolution path (or pass filters into searchVec0) so filtered searches do not return unrelated chunks.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/search/unified.ts, line 342:

<comment>Vec0 content lookup still ignores search filters. Apply `mergedFilters` to the vec0 chunk resolution path (or pass filters into `searchVec0`) so filtered searches do not return unrelated chunks.</comment>

<file context>
@@ -328,13 +328,67 @@ async function searchVec0(
+                c.chunk_index, c.kind, d.path AS source_path, d.title AS doc_title
+         FROM chunks c
+         JOIN documents d ON d.id = c.document_id
+         WHERE c.id IN (${placeholders})`,
+      )
+      .all(...chunkIds) as Array<{
</file context>

)
.all(...chunkIds) as Array<{
id: string;
content: string;
symbol: string | null;
chunk_type: string;
start_line: number | null;
end_line: number | null;
chunk_index: number;
kind: string | null;
source_path: string;
doc_title: string;
}>;

const chunkMap = new Map(chunkRows.map((r) => [r.id, r]));

return rows.slice(0, MAX_BATCH_IDS).map((row) => {
const chunk = chunkMap.get(row.chunk_id);
if (!chunk) {
// Fallback: chunk not found in chunks table (shouldn't happen, but be safe)
return {
id: row.chunk_id,
title: `vec0:${row.chunk_id.slice(0, 8)}`,
excerpt: `[vec0 chunk] distance=${row.distance.toFixed(4)}`,
score: Math.max(0, 1 - row.distance),
content_type: "chunk" as const,
};
}
const excerpt =
chunk.content.length > 80
? chunk.content.slice(0, 77) + "..."
: chunk.content;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return {
id: chunk.id,
title:
chunk.symbol ??
`${chunk.doc_title}:${chunk.chunk_type}#${chunk.chunk_index}`,
excerpt,
score: Math.max(0, 1 - row.distance),
content_type: "chunk" as const,
source_path: chunk.source_path ?? undefined,
metadata: {
kind: chunk.kind ?? undefined,
chunk_type: chunk.chunk_type,
start_line: chunk.start_line ?? undefined,
end_line: chunk.end_line ?? undefined,
},
};
});
} catch {
return [];
}
Expand Down
Loading