feat(memory): add operator retrieval plugin (#736)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/push/publish Pipeline was successful

This commit was merged in pull request #736.
This commit is contained in:
2026-07-13 12:44:31 +00:00
parent 76325ca3f2
commit 2363f155b4
8 changed files with 380 additions and 6 deletions

View File

@@ -274,6 +274,20 @@ describe('KeywordAdapter', () => {
expect(results).toHaveLength(1);
});
it('should return all scoped insights for the explicit wildcard query', async () => {
await adapter.storeInsight({
userId: 'u1',
content: 'A literal * marker is still ordinary content',
source: 'chat',
category: 'technical',
relevanceScore: 0.7,
});
const results = await adapter.searchInsights('u1', '*');
expect(results).toHaveLength(4);
expect(results.every((result) => result.score === 1)).toBe(true);
});
it('should return empty for empty query', async () => {
const results = await adapter.searchInsights('u1', ' ');
expect(results).toHaveLength(0);

View File

@@ -132,19 +132,23 @@ export class KeywordAdapter implements MemoryAdapter {
opts?: { limit?: number; embedding?: number[] },
): Promise<InsightSearchResult[]> {
const limit = opts?.limit ?? 10;
const words = query
.toLowerCase()
.split(/\s+/)
.filter((w) => w.length > 0);
const normalizedQuery = query.trim();
const matchAll = normalizedQuery === '*';
const words = matchAll
? []
: normalizedQuery
.toLowerCase()
.split(/\s+/)
.filter((word) => word.length > 0);
if (words.length === 0) return [];
if (words.length === 0 && !matchAll) return [];
const rows = await this.storage.find<InsightRecord>(INSIGHTS, { userId });
const scored: InsightSearchResult[] = [];
for (const row of rows) {
const content = row.content.toLowerCase();
let score = 0;
let score = matchAll ? 1 : 0;
for (const word of words) {
if (content.includes(word)) score++;
}