feat: Add DefaultEmbeddingFunction for local vector embeddings

- Added @chroma-core/default-embed dependency for local embeddings
- Updated ChromaSync to use DefaultEmbeddingFunction with collections
- Added isServerReachable() async method for reliable server detection
- Fixed start() to detect and reuse existing Chroma servers
- Updated build script to externalize native ONNX binaries
- Added runtime dependency to plugin/package.json

The embedding function uses all-MiniLM-L6-v2 model locally via ONNX,
eliminating need for external embedding API calls.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
bigphoot
2026-01-23 23:28:38 -08:00
committed by bigphoot
parent 70d6ac9daf
commit 2c304eafad
5 changed files with 62 additions and 9 deletions
+9 -4
View File
@@ -13,6 +13,7 @@
*/
import { ChromaClient, Collection } from 'chromadb';
import { DefaultEmbeddingFunction } from '@chroma-core/default-embed';
import { ParsedObservation, ParsedSummary } from '../../sdk/parser.js';
import { SessionStore } from '../sqlite/SessionStore.js';
import { logger } from '../../utils/logger.js';
@@ -108,11 +109,12 @@ export class ChromaSync {
const port = parseInt(settings.CLAUDE_MEM_CHROMA_PORT || '8000', 10);
const ssl = settings.CLAUDE_MEM_CHROMA_SSL === 'true';
// In local mode, verify server is running
// In local mode, verify server is reachable
if (mode === 'local') {
const serverManager = ChromaServerManager.getInstance();
if (!serverManager.isRunning()) {
throw new Error('Chroma server not running. Ensure worker started correctly.');
const reachable = await serverManager.isServerReachable();
if (!reachable) {
throw new Error('Chroma server not reachable. Ensure worker started correctly.');
}
}
@@ -159,8 +161,11 @@ export class ChromaSync {
try {
// getOrCreateCollection handles both cases
// Use DefaultEmbeddingFunction for local embeddings (all-MiniLM-L6-v2)
const embeddingFunction = new DefaultEmbeddingFunction();
this.collection = await this.chromaClient.getOrCreateCollection({
name: this.collectionName
name: this.collectionName,
embeddingFunction
});
logger.debug('CHROMA_SYNC', 'Collection ready', { collection: this.collectionName });