@memvid/sdk 2.0.151 → 2.0.153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -311,10 +311,70 @@ export declare class MistralEmbeddings implements EmbeddingProvider {
311
311
  embedDocuments(texts: string[]): Promise<number[][]>;
312
312
  embedQuery(text: string): Promise<number[]>;
313
313
  }
314
+ /**
315
+ * Ollama embedding provider configuration.
316
+ */
317
+ export interface OllamaEmbeddingsConfig {
318
+ /** Ollama server URL. Default: 'http://localhost:11434' or OLLAMA_HOST env var */
319
+ baseUrl?: string;
320
+ /** Model to use. Default: 'nomic-embed-text' */
321
+ model?: string;
322
+ /** Known embedding dimension. If omitted, auto-detected on first call. */
323
+ dimension?: number;
324
+ }
325
+ /**
326
+ * Ollama embedding provider.
327
+ *
328
+ * Uses a local Ollama server to generate embeddings. Supports any embedding model
329
+ * available in Ollama, including nomic-embed-text, mxbai-embed-large, all-minilm, etc.
330
+ *
331
+ * @example
332
+ * ```typescript
333
+ * // Default: localhost:11434 with nomic-embed-text
334
+ * const embedder = new OllamaEmbeddings();
335
+ *
336
+ * // Custom configuration
337
+ * const embedder = new OllamaEmbeddings({
338
+ * baseUrl: 'http://gpu-server:11434',
339
+ * model: 'nomic-embed-text',
340
+ * });
341
+ *
342
+ * // Use with Memvid
343
+ * const texts = ['Hello world', 'Goodbye world'];
344
+ * const embeddings = await embedder.embedDocuments(texts);
345
+ *
346
+ * // Or embed and store in one step
347
+ * const embedding = await embedder.embedQuery('Document text...');
348
+ * await mem.put({
349
+ * title: 'My Doc',
350
+ * label: 'docs',
351
+ * text: 'Document text...',
352
+ * embedding,
353
+ * embeddingIdentity: {
354
+ * provider: 'ollama',
355
+ * model: 'nomic-embed-text',
356
+ * dimension: embedding.length,
357
+ * },
358
+ * });
359
+ * ```
360
+ */
361
+ export declare class OllamaEmbeddings implements EmbeddingProvider {
362
+ private readonly _baseUrl;
363
+ private readonly _model;
364
+ private _dimension?;
365
+ constructor(config?: OllamaEmbeddingsConfig);
366
+ private static readonly OLLAMA_MODEL_DIMENSIONS;
367
+ get dimension(): number;
368
+ get modelName(): string;
369
+ get provider(): string;
370
+ private setDimensionFromEmbedding;
371
+ embedDocuments(texts: string[]): Promise<number[][]>;
372
+ embedQuery(text: string): Promise<number[]>;
373
+ }
314
374
  /**
315
375
  * Factory function to create an embedding provider.
316
376
  *
317
- * @param provider - One of: 'openai', 'cohere', 'voyage', 'nvidia', 'gemini', 'mistral'
377
+ * @param provider - One of: 'openai', 'cohere', 'voyage', 'nvidia', 'gemini', 'mistral', 'ollama'
318
378
  * @param config - Provider-specific configuration
319
379
  * @returns EmbeddingProvider instance
320
380
  *
@@ -324,6 +384,8 @@ export declare class MistralEmbeddings implements EmbeddingProvider {
324
384
  * const embedder = getEmbedder('cohere', { model: 'embed-multilingual-v3.0' });
325
385
  * const embedder = getEmbedder('gemini'); // Uses GOOGLE_API_KEY or GEMINI_API_KEY
326
386
  * const embedder = getEmbedder('mistral'); // Uses MISTRAL_API_KEY
387
+ * const embedder = getEmbedder('ollama'); // Uses local Ollama server
388
+ * const embedder = getEmbedder('ollama', { model: 'nomic-embed-text', baseUrl: 'http://gpu:11434' });
327
389
  * ```
328
390
  */
329
- export declare function getEmbedder(provider: 'openai' | 'cohere' | 'voyage' | 'nvidia' | 'gemini' | 'mistral', config?: Record<string, unknown>): EmbeddingProvider;
391
+ export declare function getEmbedder(provider: 'openai' | 'cohere' | 'voyage' | 'nvidia' | 'gemini' | 'mistral' | 'ollama', config?: Record<string, unknown>): EmbeddingProvider;
@@ -26,7 +26,7 @@
26
26
  * ```
27
27
  */
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.MistralEmbeddings = exports.GeminiEmbeddings = exports.NvidiaEmbeddings = exports.VoyageEmbeddings = exports.CohereEmbeddings = exports.OpenAIEmbeddings = exports.LOCAL_EMBEDDING_MODELS = exports.MODEL_DIMENSIONS = void 0;
29
+ exports.OllamaEmbeddings = exports.MistralEmbeddings = exports.GeminiEmbeddings = exports.NvidiaEmbeddings = exports.VoyageEmbeddings = exports.CohereEmbeddings = exports.OpenAIEmbeddings = exports.LOCAL_EMBEDDING_MODELS = exports.MODEL_DIMENSIONS = void 0;
30
30
  exports.getEmbedder = getEmbedder;
31
31
  /**
32
32
  * Model dimension mappings for common embedding models.
@@ -575,10 +575,164 @@ class MistralEmbeddings {
575
575
  }
576
576
  }
577
577
  exports.MistralEmbeddings = MistralEmbeddings;
578
+ /**
579
+ * Ollama embedding provider.
580
+ *
581
+ * Uses a local Ollama server to generate embeddings. Supports any embedding model
582
+ * available in Ollama, including nomic-embed-text, mxbai-embed-large, all-minilm, etc.
583
+ *
584
+ * @example
585
+ * ```typescript
586
+ * // Default: localhost:11434 with nomic-embed-text
587
+ * const embedder = new OllamaEmbeddings();
588
+ *
589
+ * // Custom configuration
590
+ * const embedder = new OllamaEmbeddings({
591
+ * baseUrl: 'http://gpu-server:11434',
592
+ * model: 'nomic-embed-text',
593
+ * });
594
+ *
595
+ * // Use with Memvid
596
+ * const texts = ['Hello world', 'Goodbye world'];
597
+ * const embeddings = await embedder.embedDocuments(texts);
598
+ *
599
+ * // Or embed and store in one step
600
+ * const embedding = await embedder.embedQuery('Document text...');
601
+ * await mem.put({
602
+ * title: 'My Doc',
603
+ * label: 'docs',
604
+ * text: 'Document text...',
605
+ * embedding,
606
+ * embeddingIdentity: {
607
+ * provider: 'ollama',
608
+ * model: 'nomic-embed-text',
609
+ * dimension: embedding.length,
610
+ * },
611
+ * });
612
+ * ```
613
+ */
614
+ class OllamaEmbeddings {
615
+ constructor(config = {}) {
616
+ const defaultHost = process.env.OLLAMA_HOST || 'http://localhost:11434';
617
+ this._baseUrl = (config.baseUrl || defaultHost).trim().replace(/\/+$/, '');
618
+ this._model = config.model || 'nomic-embed-text';
619
+ this._dimension = config.dimension;
620
+ }
621
+ get dimension() {
622
+ if (this._dimension)
623
+ return this._dimension;
624
+ return OllamaEmbeddings.OLLAMA_MODEL_DIMENSIONS[this._model] || 768;
625
+ }
626
+ get modelName() {
627
+ return this._model;
628
+ }
629
+ get provider() {
630
+ return 'ollama';
631
+ }
632
+ setDimensionFromEmbedding(embedding) {
633
+ if (!this._dimension && embedding.length > 0) {
634
+ this._dimension = embedding.length;
635
+ }
636
+ }
637
+ async embedDocuments(texts) {
638
+ if (texts.length === 0) {
639
+ return [];
640
+ }
641
+ // Ollama doesn't support batch embedding, so we process one at a time
642
+ // For better performance, consider using Promise.all with concurrency limit
643
+ const embeddings = [];
644
+ for (const text of texts) {
645
+ const response = await fetch(`${this._baseUrl}/api/embeddings`, {
646
+ method: 'POST',
647
+ headers: {
648
+ 'Content-Type': 'application/json',
649
+ },
650
+ body: JSON.stringify({
651
+ model: this._model,
652
+ prompt: text,
653
+ }),
654
+ });
655
+ if (!response.ok) {
656
+ const error = await response.text();
657
+ throw new Error(`Ollama API error: ${response.status} ${error}`);
658
+ }
659
+ const data = await response.json();
660
+ if (!Array.isArray(data.embedding)) {
661
+ throw new Error(`Ollama API error: invalid response format`);
662
+ }
663
+ this.setDimensionFromEmbedding(data.embedding);
664
+ embeddings.push(data.embedding);
665
+ }
666
+ return embeddings;
667
+ }
668
+ async embedQuery(text) {
669
+ const response = await fetch(`${this._baseUrl}/api/embeddings`, {
670
+ method: 'POST',
671
+ headers: {
672
+ 'Content-Type': 'application/json',
673
+ },
674
+ body: JSON.stringify({
675
+ model: this._model,
676
+ prompt: text,
677
+ }),
678
+ });
679
+ if (!response.ok) {
680
+ const error = await response.text();
681
+ throw new Error(`Ollama API error: ${response.status} ${error}`);
682
+ }
683
+ const data = await response.json();
684
+ if (!Array.isArray(data.embedding)) {
685
+ throw new Error(`Ollama API error: invalid response format`);
686
+ }
687
+ this.setDimensionFromEmbedding(data.embedding);
688
+ return data.embedding;
689
+ }
690
+ }
691
+ exports.OllamaEmbeddings = OllamaEmbeddings;
692
+ // Known model dimensions for popular Ollama embedding models
693
+ OllamaEmbeddings.OLLAMA_MODEL_DIMENSIONS = {
694
+ // General purpose
695
+ 'nomic-embed-text': 768,
696
+ 'nomic-embed-text:v1': 768,
697
+ 'nomic-embed-text:v1.5': 768,
698
+ 'mxbai-embed-large': 1024,
699
+ 'mxbai-embed-large:v1': 1024,
700
+ 'all-minilm': 384,
701
+ 'all-minilm:l6-v2': 384,
702
+ 'all-minilm:l12-v2': 384,
703
+ // Snowflake Arctic (various sizes)
704
+ 'snowflake-arctic-embed': 1024,
705
+ 'snowflake-arctic-embed:s': 384,
706
+ 'snowflake-arctic-embed:m': 768,
707
+ 'snowflake-arctic-embed:l': 1024,
708
+ 'snowflake-arctic-embed:335m': 1024,
709
+ // BGE models
710
+ 'bge-m3': 1024,
711
+ 'bge-large': 1024,
712
+ 'bge-large:en': 1024,
713
+ 'bge-large:en-v1.5': 1024,
714
+ 'bge-base': 768,
715
+ 'bge-base:en': 768,
716
+ 'bge-base:en-v1.5': 768,
717
+ 'bge-small': 384,
718
+ 'bge-small:en': 384,
719
+ 'bge-small:en-v1.5': 384,
720
+ // Jina embeddings
721
+ 'jina-embeddings-v2-base-en': 768,
722
+ 'jina-embeddings-v2-small-en': 512,
723
+ // Multilingual
724
+ 'paraphrase-multilingual': 768,
725
+ 'paraphrase-multilingual:mpnet-base-v2': 768,
726
+ // E5 models
727
+ 'e5-large': 1024,
728
+ 'e5-base': 768,
729
+ 'e5-small': 384,
730
+ 'e5-mistral-7b-instruct': 4096,
731
+ };
578
732
  /**
579
733
  * Factory function to create an embedding provider.
580
734
  *
581
- * @param provider - One of: 'openai', 'cohere', 'voyage', 'nvidia', 'gemini', 'mistral'
735
+ * @param provider - One of: 'openai', 'cohere', 'voyage', 'nvidia', 'gemini', 'mistral', 'ollama'
582
736
  * @param config - Provider-specific configuration
583
737
  * @returns EmbeddingProvider instance
584
738
  *
@@ -588,6 +742,8 @@ exports.MistralEmbeddings = MistralEmbeddings;
588
742
  * const embedder = getEmbedder('cohere', { model: 'embed-multilingual-v3.0' });
589
743
  * const embedder = getEmbedder('gemini'); // Uses GOOGLE_API_KEY or GEMINI_API_KEY
590
744
  * const embedder = getEmbedder('mistral'); // Uses MISTRAL_API_KEY
745
+ * const embedder = getEmbedder('ollama'); // Uses local Ollama server
746
+ * const embedder = getEmbedder('ollama', { model: 'nomic-embed-text', baseUrl: 'http://gpu:11434' });
591
747
  * ```
592
748
  */
593
749
  function getEmbedder(provider, config) {
@@ -605,7 +761,9 @@ function getEmbedder(provider, config) {
605
761
  return new GeminiEmbeddings(config);
606
762
  case 'mistral':
607
763
  return new MistralEmbeddings(config);
764
+ case 'ollama':
765
+ return new OllamaEmbeddings(config);
608
766
  default:
609
- throw new Error(`Unknown provider: ${provider}. Supported: openai, cohere, voyage, nvidia, gemini, mistral`);
767
+ throw new Error(`Unknown provider: ${provider}. Supported: openai, cohere, voyage, nvidia, gemini, mistral, ollama`);
610
768
  }
611
769
  }
package/dist/index.d.ts CHANGED
@@ -409,7 +409,7 @@ export declare function verifyMemvid(path: string, options?: UseVerifyOptions):
409
409
  export declare function doctorMemvid(path: string, options?: UseDoctorOptions): Promise<unknown>;
410
410
  export type { AddMemoryCardsResult, Kind, ApiKey, Memvid, MemoryCard, MemoryCardInput, MemoriesResult, MemoriesStats, LockOptions, UseOptions, UnlockOptions, FindInput, VecSearchInput, AskInput, TimelineInput, PutInput, PutManyInput, PutManyOptions, MemvidErrorCode, MemvidErrorDetails, HeatmapEntry, HeatmapResponse, SessionSummary, SessionReplayResult, SessionActionResult, StatsResult, FindHit, FindResult, VecSearchResult, AskResult, AskStats, AskUsage, AskSource, Grounding, FollowUp, TimelineEntry, } from "./types";
411
411
  export { MemvidError, CapacityExceededError, TicketInvalidError, TicketReplayError, LexIndexDisabledError, TimeIndexMissingError, VerificationFailedError, LockedError, ApiKeyRequiredError, FileNotFoundError, MemoryAlreadyBoundError, FrameNotFoundError, VecIndexDisabledError, CorruptFileError, VecDimensionMismatchError, EmbeddingFailedError, EncryptionError, QuotaExceededError, getErrorSuggestion, } from "./error";
412
- export { EmbeddingProvider, OpenAIEmbeddings, OpenAIEmbeddingsConfig, CohereEmbeddings, CohereEmbeddingsConfig, VoyageEmbeddings, VoyageEmbeddingsConfig, NvidiaEmbeddings, NvidiaEmbeddingsConfig, GeminiEmbeddings, GeminiEmbeddingsConfig, MistralEmbeddings, MistralEmbeddingsConfig, getEmbedder, MODEL_DIMENSIONS, LOCAL_EMBEDDING_MODELS, LocalEmbeddingModel, } from "./embeddings";
412
+ export { EmbeddingProvider, OpenAIEmbeddings, OpenAIEmbeddingsConfig, CohereEmbeddings, CohereEmbeddingsConfig, VoyageEmbeddings, VoyageEmbeddingsConfig, NvidiaEmbeddings, NvidiaEmbeddingsConfig, GeminiEmbeddings, GeminiEmbeddingsConfig, MistralEmbeddings, MistralEmbeddingsConfig, OllamaEmbeddings, OllamaEmbeddingsConfig, getEmbedder, MODEL_DIMENSIONS, LOCAL_EMBEDDING_MODELS, LocalEmbeddingModel, } from "./embeddings";
413
413
  export { flush as flushAnalytics, isTelemetryEnabled } from "./analytics";
414
414
  /**
415
415
  * Mask PII (Personally Identifiable Information) in text.
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.isTelemetryEnabled = exports.flushAnalytics = exports.LOCAL_EMBEDDING_MODELS = exports.MODEL_DIMENSIONS = exports.getEmbedder = exports.MistralEmbeddings = exports.GeminiEmbeddings = exports.NvidiaEmbeddings = exports.VoyageEmbeddings = exports.CohereEmbeddings = exports.OpenAIEmbeddings = exports.getErrorSuggestion = exports.QuotaExceededError = exports.EncryptionError = exports.EmbeddingFailedError = exports.VecDimensionMismatchError = exports.CorruptFileError = exports.VecIndexDisabledError = exports.FrameNotFoundError = exports.MemoryAlreadyBoundError = exports.FileNotFoundError = exports.ApiKeyRequiredError = exports.LockedError = exports.VerificationFailedError = exports.TimeIndexMissingError = exports.LexIndexDisabledError = exports.TicketReplayError = exports.TicketInvalidError = exports.CapacityExceededError = exports.MemvidError = exports.use = exports.GeminiEntities = exports.ClaudeEntities = exports.OpenAIEntities = exports.LocalNER = exports.getEntityExtractor = exports.GeminiClip = exports.OpenAIClip = exports.LocalClip = exports.getClipProvider = exports.entities = exports.clip = void 0;
39
+ exports.isTelemetryEnabled = exports.flushAnalytics = exports.LOCAL_EMBEDDING_MODELS = exports.MODEL_DIMENSIONS = exports.getEmbedder = exports.OllamaEmbeddings = exports.MistralEmbeddings = exports.GeminiEmbeddings = exports.NvidiaEmbeddings = exports.VoyageEmbeddings = exports.CohereEmbeddings = exports.OpenAIEmbeddings = exports.getErrorSuggestion = exports.QuotaExceededError = exports.EncryptionError = exports.EmbeddingFailedError = exports.VecDimensionMismatchError = exports.CorruptFileError = exports.VecIndexDisabledError = exports.FrameNotFoundError = exports.MemoryAlreadyBoundError = exports.FileNotFoundError = exports.ApiKeyRequiredError = exports.LockedError = exports.VerificationFailedError = exports.TimeIndexMissingError = exports.LexIndexDisabledError = exports.TicketReplayError = exports.TicketInvalidError = exports.CapacityExceededError = exports.MemvidError = exports.use = exports.GeminiEntities = exports.ClaudeEntities = exports.OpenAIEntities = exports.LocalNER = exports.getEntityExtractor = exports.GeminiClip = exports.OpenAIClip = exports.LocalClip = exports.getClipProvider = exports.entities = exports.clip = void 0;
40
40
  exports.configure = configure;
41
41
  exports.getConfig = getConfig;
42
42
  exports.resetConfig = resetConfig;
@@ -829,6 +829,8 @@ function normalisePutArgs(input) {
829
829
  extractDates: input.extractDates,
830
830
  vectorCompression: input.vectorCompression,
831
831
  timestamp: input.timestamp,
832
+ embedding: input.embedding,
833
+ embeddingIdentity: input.embeddingIdentity,
832
834
  };
833
835
  return payload;
834
836
  }
@@ -2268,6 +2270,7 @@ Object.defineProperty(exports, "VoyageEmbeddings", { enumerable: true, get: func
2268
2270
  Object.defineProperty(exports, "NvidiaEmbeddings", { enumerable: true, get: function () { return embeddings_1.NvidiaEmbeddings; } });
2269
2271
  Object.defineProperty(exports, "GeminiEmbeddings", { enumerable: true, get: function () { return embeddings_1.GeminiEmbeddings; } });
2270
2272
  Object.defineProperty(exports, "MistralEmbeddings", { enumerable: true, get: function () { return embeddings_1.MistralEmbeddings; } });
2273
+ Object.defineProperty(exports, "OllamaEmbeddings", { enumerable: true, get: function () { return embeddings_1.OllamaEmbeddings; } });
2271
2274
  Object.defineProperty(exports, "getEmbedder", { enumerable: true, get: function () { return embeddings_1.getEmbedder; } });
2272
2275
  Object.defineProperty(exports, "MODEL_DIMENSIONS", { enumerable: true, get: function () { return embeddings_1.MODEL_DIMENSIONS; } });
2273
2276
  Object.defineProperty(exports, "LOCAL_EMBEDDING_MODELS", { enumerable: true, get: function () { return embeddings_1.LOCAL_EMBEDDING_MODELS; } });
package/dist/types.d.ts CHANGED
@@ -43,6 +43,10 @@ export interface PutInput {
43
43
  * "Jan 15, 2023", "2023-01-15", "01/15/2023"
44
44
  */
45
45
  timestamp?: number | string;
46
+ /** Optional pre-computed embedding vector (use with external embedding providers like Ollama) */
47
+ embedding?: number[];
48
+ /** Optional embedding identity metadata for `embedding` (enables CLI/SDK auto-detection). */
49
+ embeddingIdentity?: EmbeddingIdentity;
46
50
  }
47
51
  export interface FindInput {
48
52
  /**
@@ -211,6 +215,10 @@ export interface NativePutArgs {
211
215
  vectorCompression?: boolean;
212
216
  /** Timestamp (epoch seconds or human-readable string) */
213
217
  timestamp?: number | string;
218
+ /** Optional pre-computed embedding vector */
219
+ embedding?: number[];
220
+ /** Optional embedding identity metadata */
221
+ embeddingIdentity?: EmbeddingIdentity;
214
222
  }
215
223
  export interface NativeFindOptions {
216
224
  k?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memvid/sdk",
3
- "version": "2.0.151",
3
+ "version": "2.0.153",
4
4
  "description": "Single-file AI memory system for Node.js. Store, search, and query documents with built-in RAG.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -41,11 +41,11 @@
41
41
  "node": ">=18"
42
42
  },
43
43
  "optionalDependencies": {
44
- "@memvid/sdk-darwin-arm64": "2.0.151",
45
- "@memvid/sdk-darwin-x64": "2.0.151",
46
- "@memvid/sdk-linux-x64-gnu": "2.0.151",
47
- "@memvid/sdk-linux-arm64-gnu": "2.0.151",
48
- "@memvid/sdk-win32-x64-msvc": "2.0.151"
44
+ "@memvid/sdk-darwin-arm64": "2.0.153",
45
+ "@memvid/sdk-darwin-x64": "2.0.153",
46
+ "@memvid/sdk-linux-x64-gnu": "2.0.153",
47
+ "@memvid/sdk-linux-arm64-gnu": "2.0.153",
48
+ "@memvid/sdk-win32-x64-msvc": "2.0.153"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@langchain/core": ">=0.3.0",