Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

add pgvector conversion helpers to db.js, refactor memory.js imports

Adam Eivya42133d0016c
diff --git a/server/lib/db.js b/server/lib/db.js
index 90721dcc2b..839777abf0 100644
--- a/server/lib/db.js
+++ b/server/lib/db.js
@@ -87,3 +87,24 @@ export async function checkHealth() {
export async function close() {
await pool.end();
}
+
+/**
+ * Convert pgvector string representation to float array.
+ * pgvector returns vectors as '[0.1,0.2,...]' strings.
+ */
+export function pgvectorToArray(vec) {
+ if (Array.isArray(vec)) return vec;
+ if (typeof vec === 'string') {
+ return vec.replace(/^\[|\]$/g, '').split(',').map(Number);
+ }
+ return null;
+}
+
+/**
+ * Format a float array (or pgvector string) as pgvector literal '[0.1,0.2,...]'
+ */
+export function arrayToPgvector(arr) {
+ if (!arr) return null;
+ if (typeof arr === 'string') return arr;
+ return `[${arr.join(',')}]`;
+}
diff --git a/server/services/memory.js b/server/services/memory.js
index a441f9bf97..d08e08f3c0 100644
--- a/server/services/memory.js
+++ b/server/services/memory.js
@@ -10,13 +10,13 @@ import { existsSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { v4 as uuidv4 } from 'uuid';
-import { cosEvents, updateAgent } from './cos.js';
-import { findTopK, findAboveThreshold, clusterBySimilarity, cosineSimilarity } from '../lib/vectorMath.js';
+import { cosEvents } from './cos.js';
+import { findTopK, findAboveThreshold, clusterBySimilarity } from '../lib/vectorMath.js';
import * as notifications from './notifications.js';
import { readJSONFile } from '../lib/fileUtils.js';
import * as memoryBM25 from './memoryBM25.js';
import { createMutex } from '../lib/asyncMutex.js';
-import { DEFAULT_MEMORY_CONFIG } from './memoryConfig.js';
+import { DEFAULT_MEMORY_CONFIG, generateSummary, decrementAgentPendingApproval } from './memoryConfig.js';
export { DEFAULT_MEMORY_CONFIG };
@@ -121,15 +121,6 @@ async function deleteMemoryFiles(id) {
}
}
-/**
- * Generate summary from content using simple truncation
- * Note: LLM-based summaries could improve quality but add latency and cost
- */
-function generateSummary(content, maxLength = 150) {
- if (content.length <= maxLength) return content;
- return content.substring(0, maxLength - 3) + '...';
-}
-
/**
* Create a new memory
*/
@@ -408,27 +399,6 @@ export async function deleteMemory(id, hard = false) {
});
}
-/**
- * Helper to decrement agent's pendingApproval count
- */
-async function decrementAgentPendingApproval(sourceAgentId) {
- if (!sourceAgentId) return;
-
- const { getAgent } = await import('./cos.js');
- const agent = await getAgent(sourceAgentId).catch(() => null);
- if (!agent?.memoryExtraction?.pendingApproval) return;
-
- const currentPending = agent.memoryExtraction.pendingApproval;
- if (currentPending > 0) {
- await updateAgent(sourceAgentId, {
- memoryExtraction: {
- ...agent.memoryExtraction,
- pendingApproval: currentPending - 1
- }
- });
- }
-}
-
/**
* Approve a pending memory (changes status from pending_approval to active)
*/