Skip to content
Closed
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
21 changes: 16 additions & 5 deletions src/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,23 @@ class KnowledgeGraphManager {
async searchNodes(query: string): Promise<KnowledgeGraph> {
const graph = await this.loadGraph();

// Map to safe lower case
function toSafeLowerCase(str: unknown): string {
if (typeof str !== 'string') return '';
return str.trim().toLowerCase();
}

// Filter entities
const filteredEntities = graph.entities.filter(e =>
e.name.toLowerCase().includes(query.toLowerCase()) ||
e.entityType.toLowerCase().includes(query.toLowerCase()) ||
e.observations.some(o => o.toLowerCase().includes(query.toLowerCase()))
);
const filteredEntities = graph.entities.filter(e => {
const lowerQuery = toSafeLowerCase(query);

return (
toSafeLowerCase(e.name).includes(lowerQuery) ||
toSafeLowerCase(e.entityType).includes(lowerQuery) ||
(Array.isArray(e.observations) &&
e.observations.some(o => toSafeLowerCase(o).includes(lowerQuery)))
);
});

// Create a Set of filtered entity names for quick lookup
const filteredEntityNames = new Set(filteredEntities.map(e => e.name));
Expand Down