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
3 changes: 2 additions & 1 deletion src/functions/smart-search.ts
Comment thread
reevesc88 marked this conversation as resolved.
Resolved
Comment thread
reevesc88 marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ export function registerSmartSearchFunction(
const compact: CompactSearchResult[] = await Promise.all(filteredHybrid.map(async (r) => {
const layer = r.layer ?? getSearchIndex().layerOf(r.observation.id) ?? getSearchResultLayer(r.observation.id, r.sessionId);
const memoryType = layer === "memory"
? (await kv.get<Memory>(KV.memories, r.observation.id).catch(() => null))?.type ?? r.observation.memoryType
? r.observation.memoryType
?? (await kv.get<Memory>(KV.memories, r.observation.id).catch(() => null))?.type
: undefined;
return {
obsId: r.observation.id,
Expand Down
13 changes: 11 additions & 2 deletions test/memory-type-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,23 @@ function fixture(saved: Memory, legacy = false, failMemoryReads = false) {
bm25Score: 1, vectorScore: 0, graphScore: 0,
}]);
registerSmartSearchFunction(sdk as unknown as IIIClient, kv as unknown as StateKV, search);
return { call: (args: object) => handler(args), saved };
return { call: (args: object) => handler(args), saved, kv };
}

describe("original memory type metadata", () => {
it("keeps compact search working when the stored memory read fails", async () => {
it("skips stored-memory reads when the search index already carries memoryType", async () => {
const f = fixture(memory("bug"), false, true);
const get = vi.spyOn(f.kv, "get");
const compact = await f.call({ query: "Synthetic", agentId: "*", targetLayer: "memory", includeLessons: false });
expect(compact.results[0]).toMatchObject({ obsId: f.saved.id, type: "decision", memoryType: "bug" });
expect(get).not.toHaveBeenCalledWith("mem:memories", f.saved.id);
});

it("keeps compact search working when a legacy index forces a stored-memory read that fails", async () => {
const f = fixture(memory("bug"), true, true);
const compact = await f.call({ query: "Synthetic", agentId: "*", targetLayer: "memory", includeLessons: false });
expect(compact.results[0]).toMatchObject({ obsId: f.saved.id, type: "decision" });
expect(compact.results[0]).not.toHaveProperty("memoryType");
});

it.each(types)("preserves %s without changing the observation type or input", (type) => {
Expand Down
Loading