Skip to content
Closed
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
18 changes: 15 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2555,16 +2555,28 @@ const memoryLanceDBProPlugin = {
);
await mkdir(backupDir, { recursive: true });

const allMemories = await store.list(undefined, undefined, 10000, 0);
// Include vectors so backup can be restored without re-embedding
const allMemories = await store.list(undefined, undefined, 10000, 0, true);
if (allMemories.length === 0) return;

const dateStr = new Date().toISOString().split("T")[0];
const backupFile = join(backupDir, `memory-backup-${dateStr}.jsonl`);

const lines = allMemories.map((m) =>
// First line: metadata header for restore compatibility
const embeddingModel = config.embedding.model || "text-embedding-3-small";
const metaLine = JSON.stringify({
_meta: true,
version: "1.1",
model: embeddingModel,
dimensions: vectorDim,
timestamp: new Date().toISOString(),
});

const dataLines = allMemories.map((m) =>
JSON.stringify({
id: m.id,
text: m.text,
vector: m.vector,
category: m.category,
scope: m.scope,
importance: m.importance,
Expand All @@ -2573,7 +2585,7 @@ const memoryLanceDBProPlugin = {
}),
);

await writeFile(backupFile, lines.join("\n") + "\n");
await writeFile(backupFile, metaLine + "\n" + dataLines.join("\n") + "\n");

// Keep only last 7 backups
const files = (await readdir(backupDir))
Expand Down
29 changes: 19 additions & 10 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ export class MemoryStore {
category?: string,
limit = 20,
offset = 0,
includeVectors = false,
): Promise<MemoryEntry[]> {
await this.ensureInitialized();

Expand All @@ -615,25 +616,33 @@ export class MemoryStore {
query = query.where(conditions.join(" AND "));
}

// Select columns - optionally include the vector column for backup/export
const selectCols = [
"id",
"text",
"category",
"scope",
"importance",
"timestamp",
"metadata",
];
if (includeVectors) {
selectCols.push("vector");
}

// Fetch all matching rows (no pre-limit) so app-layer sort is correct across full dataset
const results = await query
.select([
"id",
"text",
"category",
"scope",
"importance",
"timestamp",
"metadata",
])
.select(selectCols)
.toArray();

return results
.map(
(row): MemoryEntry => ({
id: row.id as string,
text: row.text as string,
vector: [], // Don't include vectors in list results for performance
vector: includeVectors && row.vector
? Array.from(row.vector as Iterable<number>)
: [],
category: row.category as MemoryEntry["category"],
scope: (row.scope as string | undefined) ?? "global",
importance: Number(row.importance),
Expand Down