feat(memory): add operator retrieval plugin (#736)
This commit was merged in pull request #736.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user