Fix export/import feature: JSON format and project filtering

Two critical fixes for the memory export/import feature:

1. **SearchManager empty results bug**: The /api/search endpoint
   with format=json now returns {observations: [], sessions: [],
   prompts: []} when no results are found, instead of the MCP
   protocol format. This fixes the export-memories script which
   expects consistent JSON structure regardless of result count.

2. **Project filtering support**: Updated SessionStore methods
   (getObservationsByIds, getSessionSummariesByIds, getUserPromptsByIds)
   to accept and apply project filter parameter. This enables
   proper project-based filtering during ChromaDB hybrid search
   result hydration.

Testing:
- Export with results:  50 observations exported
- Export with empty results:  Proper JSON structure
- Round-trip import:  Duplicate prevention working
- Project filtering:  claude-mem (51 obs) vs rad-mem (1 obs)

Fixes export/import feature blocking bugs.
This commit is contained in:
Alex Newman
2025-12-10 18:04:49 -05:00
parent fa93f2c1e2
commit 73be8f7a63
2 changed files with 87 additions and 12 deletions
+16
View File
@@ -198,6 +198,13 @@ export class SearchManager {
const totalResults = observations.length + sessions.length + prompts.length;
if (totalResults === 0) {
if (format === 'json') {
return {
observations: [],
sessions: [],
prompts: []
};
}
return {
content: [{
type: 'text' as const,
@@ -230,6 +237,15 @@ export class SearchManager {
const limitedResults = allResults.slice(0, options.limit || 20);
// Format based on requested format
if (format === 'json') {
// Raw JSON format for exports
return {
observations,
sessions,
prompts
};
}
let combinedText: string;
if (format === 'index') {
const header = `Found ${totalResults} result(s) matching "${query}" (${observations.length} obs, ${sessions.length} sessions, ${prompts.length} prompts):\n\n`;