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
31 changes: 31 additions & 0 deletions apps/server/src/orchestration-v2/ThreadSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,37 @@ it.layer(layerTest)("ThreadSearch.searchThreads", (it) => {
}),
);

it.effect("keeps a better title match over a weaker one found by its messages", () =>
Effect.gen(function* () {
const projections = yield* ProjectionStore.ProjectionStoreV2;
const search = yield* ThreadSearch.ThreadSearch;
const project = ProjectId.make("project:heron");
yield* createProject(project);
// Six titled threads that each also name the word in a message.
yield* Effect.forEach(
Array.from({ length: 6 }, (_, index) => {
const id = ThreadId.make(`thread:heron-${index + 1}`);
return [
thread(id, project, { title: `Heron ${index + 1}` }),
message(id, `heron-${index + 1}`, "user", "a heron sighting", { minute: 2 }),
];
}).flat(),
projections.apply,
{ discard: true },
);
const byTitle = (yield* search.searchThreads({ query: "heron", limit: 6 })).matches;
assert.deepStrictEqual(
byTitle.map((match) => match.source),
Array.from({ length: 6 }, () => "title"),
);
const { matches } = yield* search.searchThreads({ query: "heron", limit: 5 });
assert.deepStrictEqual(
matches.map((match) => match.threadId),
byTitle.slice(0, 5).map((match) => match.threadId),
);
}),
);

it.effect("leaves titled threads out before the hit limit", () =>
Effect.gen(function* () {
const projections = yield* ProjectionStore.ProjectionStoreV2;
Expand Down
21 changes: 11 additions & 10 deletions apps/server/src/orchestration-v2/ThreadSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,21 +660,22 @@ export const make = Effect.gen(function* () {
},
]),
);
const titleHits: ThreadSearchHit[] = rankSearchItems(candidates, (row, options) =>
const titleRanked = rankSearchItems(candidates, (row, options) =>
// An agent's search has no use for the user's palette picks.
scoreThreadSearch(normalizedQuery, subjectById.get(row.thread.id)!, now, {
...options,
picks: false,
}),
)
.slice(0, limit)
.map(({ item }) => ({
threadId: item.thread.id,
projectId: item.thread.projectId,
title: item.thread.title,
source: "title",
}));
const shown = new Set(titleHits.map((hit) => hit.threadId));
);
const titleHits: ThreadSearchHit[] = titleRanked.slice(0, limit).map(({ item }) => ({
threadId: item.thread.id,
projectId: item.thread.projectId,
title: item.thread.title,
source: "title",
}));
// The message slots are for threads the titles miss: a weaker title match
// found again by its messages would push out a better one.
const shown = new Set(titleRanked.map(({ item }) => item.thread.id));
const { matches } = yield* searchMessages({
query: input.query,
limit: 50,
Expand Down
Loading