Skip to content

Commit 87147b6

Browse files
authored
perf(recall): stop materializing the unused embedding BLOB in entity SELECTs (#231)
The recall, get, timeline, and dense-hydrate SELECTs all listed the embedding column, but entity_from_row never reads it (it skips that position and sets embedding: None). So every returned row materialized and copied the ~1.5 KB embedding BLOB off the page cache only to discard it: ~15 KB per default limit-10 recall, up to ~1.5 MB for limit-1000 browse/list calls. Project NULL in that column position instead of the stored BLOB. The column position is preserved so entity_from_row's positional indices are unchanged; dense_search's phase-1 `SELECT id, embedding` scan (which actually needs the vector) is untouched. Behavior is identical; existing recall/get/timeline tests confirm no column misalignment. Closes #229
1 parent 455b1d9 commit 87147b6

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/db.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ impl Database {
774774
"SELECT id, category, key, body_json, status, type, tags,
775775
decay_score, retrieval_count, layer, topic_path,
776776
archived, archive_reason, links, verified, source,
777-
created_at_unix_ms, last_accessed_unix_ms, embedding,
777+
created_at_unix_ms, last_accessed_unix_ms, NULL as embedding,
778778
always_on, certainty, workspace_hash, agent_id, visibility
779779
FROM entities WHERE id IN ({})",
780780
placeholders
@@ -1402,7 +1402,7 @@ impl Database {
14021402
"SELECT id, category, key, body_json, status, type, tags,
14031403
decay_score, retrieval_count, layer, topic_path,
14041404
archived, archive_reason, links, verified, source,
1405-
created_at_unix_ms, last_accessed_unix_ms, embedding,
1405+
created_at_unix_ms, last_accessed_unix_ms, NULL as embedding,
14061406
always_on, certainty, workspace_hash, agent_id, visibility
14071407
FROM entities",
14081408
);
@@ -1602,7 +1602,7 @@ impl Database {
16021602
"SELECT id, category, key, body_json, status, type, tags,
16031603
decay_score, retrieval_count, layer, topic_path,
16041604
archived, archive_reason, links, verified, source,
1605-
created_at_unix_ms, last_accessed_unix_ms, embedding,
1605+
created_at_unix_ms, last_accessed_unix_ms, NULL as embedding,
16061606
always_on, certainty, workspace_hash, agent_id, visibility
16071607
FROM entities WHERE category = ?1 AND key = ?2 LIMIT 1",
16081608
)?;
@@ -2270,7 +2270,7 @@ impl Database {
22702270
"SELECT id, category, key, body_json, status, type, tags,
22712271
decay_score, retrieval_count, layer, topic_path,
22722272
archived, archive_reason, links, verified, source,
2273-
created_at_unix_ms, last_accessed_unix_ms, embedding,
2273+
created_at_unix_ms, last_accessed_unix_ms, NULL as embedding,
22742274
always_on, certainty, workspace_hash, agent_id, visibility
22752275
FROM entities WHERE id = ?1",
22762276
)?;
@@ -2305,7 +2305,7 @@ impl Database {
23052305
"SELECT id, category, key, body_json, status, type, tags,
23062306
decay_score, retrieval_count, layer, topic_path,
23072307
archived, archive_reason, links, verified, source,
2308-
created_at_unix_ms, last_accessed_unix_ms, embedding,
2308+
created_at_unix_ms, last_accessed_unix_ms, NULL as embedding,
23092309
always_on, certainty, workspace_hash, agent_id, visibility
23102310
FROM entities WHERE archived = 0",
23112311
);
@@ -3072,7 +3072,7 @@ last_accessed: {}
30723072
let sql = "SELECT id, category, key, body_json, status, type, tags,
30733073
decay_score, retrieval_count, layer, topic_path,
30743074
archived, archive_reason, links, verified, source,
3075-
created_at_unix_ms, last_accessed_unix_ms, embedding,
3075+
created_at_unix_ms, last_accessed_unix_ms, NULL as embedding,
30763076
always_on, certainty, workspace_hash, agent_id, visibility
30773077
FROM entities
30783078
WHERE archived = 0

0 commit comments

Comments
 (0)