mem0ai 2.1.29 → 2.1.30
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.
- package/dist/oss/index.d.mts +39 -1
- package/dist/oss/index.d.ts +39 -1
- package/dist/oss/index.js +381 -4
- package/dist/oss/index.js.map +1 -1
- package/dist/oss/index.mjs +379 -3
- package/dist/oss/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/oss/index.d.mts
CHANGED
|
@@ -106,14 +106,17 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
106
106
|
modelProperties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
107
107
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
108
108
|
model: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodAny]>>;
|
|
109
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
109
110
|
}, "strip", z.ZodTypeAny, {
|
|
110
111
|
modelProperties?: Record<string, any> | undefined;
|
|
111
112
|
apiKey?: string | undefined;
|
|
112
113
|
model?: any;
|
|
114
|
+
baseURL?: string | undefined;
|
|
113
115
|
}, {
|
|
114
116
|
modelProperties?: Record<string, any> | undefined;
|
|
115
117
|
apiKey?: string | undefined;
|
|
116
118
|
model?: any;
|
|
119
|
+
baseURL?: string | undefined;
|
|
117
120
|
}>;
|
|
118
121
|
}, "strip", z.ZodTypeAny, {
|
|
119
122
|
provider: string;
|
|
@@ -121,6 +124,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
121
124
|
modelProperties?: Record<string, any> | undefined;
|
|
122
125
|
apiKey?: string | undefined;
|
|
123
126
|
model?: any;
|
|
127
|
+
baseURL?: string | undefined;
|
|
124
128
|
};
|
|
125
129
|
}, {
|
|
126
130
|
provider: string;
|
|
@@ -128,6 +132,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
128
132
|
modelProperties?: Record<string, any> | undefined;
|
|
129
133
|
apiKey?: string | undefined;
|
|
130
134
|
model?: any;
|
|
135
|
+
baseURL?: string | undefined;
|
|
131
136
|
};
|
|
132
137
|
}>;
|
|
133
138
|
vectorStore: z.ZodObject<{
|
|
@@ -170,14 +175,17 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
170
175
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
171
176
|
model: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodAny]>>;
|
|
172
177
|
modelProperties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
178
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
173
179
|
}, "strip", z.ZodTypeAny, {
|
|
174
180
|
modelProperties?: Record<string, any> | undefined;
|
|
175
181
|
apiKey?: string | undefined;
|
|
176
182
|
model?: any;
|
|
183
|
+
baseURL?: string | undefined;
|
|
177
184
|
}, {
|
|
178
185
|
modelProperties?: Record<string, any> | undefined;
|
|
179
186
|
apiKey?: string | undefined;
|
|
180
187
|
model?: any;
|
|
188
|
+
baseURL?: string | undefined;
|
|
181
189
|
}>;
|
|
182
190
|
}, "strip", z.ZodTypeAny, {
|
|
183
191
|
provider: string;
|
|
@@ -185,6 +193,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
185
193
|
modelProperties?: Record<string, any> | undefined;
|
|
186
194
|
apiKey?: string | undefined;
|
|
187
195
|
model?: any;
|
|
196
|
+
baseURL?: string | undefined;
|
|
188
197
|
};
|
|
189
198
|
}, {
|
|
190
199
|
provider: string;
|
|
@@ -192,6 +201,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
192
201
|
modelProperties?: Record<string, any> | undefined;
|
|
193
202
|
apiKey?: string | undefined;
|
|
194
203
|
model?: any;
|
|
204
|
+
baseURL?: string | undefined;
|
|
195
205
|
};
|
|
196
206
|
}>;
|
|
197
207
|
historyDbPath: z.ZodOptional<z.ZodString>;
|
|
@@ -266,6 +276,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
266
276
|
modelProperties?: Record<string, any> | undefined;
|
|
267
277
|
apiKey?: string | undefined;
|
|
268
278
|
model?: any;
|
|
279
|
+
baseURL?: string | undefined;
|
|
269
280
|
};
|
|
270
281
|
};
|
|
271
282
|
vectorStore: {
|
|
@@ -284,6 +295,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
284
295
|
modelProperties?: Record<string, any> | undefined;
|
|
285
296
|
apiKey?: string | undefined;
|
|
286
297
|
model?: any;
|
|
298
|
+
baseURL?: string | undefined;
|
|
287
299
|
};
|
|
288
300
|
};
|
|
289
301
|
version?: string | undefined;
|
|
@@ -315,6 +327,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
315
327
|
modelProperties?: Record<string, any> | undefined;
|
|
316
328
|
apiKey?: string | undefined;
|
|
317
329
|
model?: any;
|
|
330
|
+
baseURL?: string | undefined;
|
|
318
331
|
};
|
|
319
332
|
};
|
|
320
333
|
vectorStore: {
|
|
@@ -333,6 +346,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
333
346
|
modelProperties?: Record<string, any> | undefined;
|
|
334
347
|
apiKey?: string | undefined;
|
|
335
348
|
model?: any;
|
|
349
|
+
baseURL?: string | undefined;
|
|
336
350
|
};
|
|
337
351
|
};
|
|
338
352
|
version?: string | undefined;
|
|
@@ -704,6 +718,30 @@ declare class LangchainVectorStore implements VectorStore {
|
|
|
704
718
|
initialize(): Promise<void>;
|
|
705
719
|
}
|
|
706
720
|
|
|
721
|
+
interface VectorizeConfig extends VectorStoreConfig {
|
|
722
|
+
apiKey?: string;
|
|
723
|
+
indexName: string;
|
|
724
|
+
accountId: string;
|
|
725
|
+
}
|
|
726
|
+
declare class VectorizeDB implements VectorStore {
|
|
727
|
+
private client;
|
|
728
|
+
private dimensions;
|
|
729
|
+
private indexName;
|
|
730
|
+
private accountId;
|
|
731
|
+
constructor(config: VectorizeConfig);
|
|
732
|
+
insert(vectors: number[][], ids: string[], payloads: Record<string, any>[]): Promise<void>;
|
|
733
|
+
search(query: number[], limit?: number, filters?: SearchFilters): Promise<VectorStoreResult[]>;
|
|
734
|
+
get(vectorId: string): Promise<VectorStoreResult | null>;
|
|
735
|
+
update(vectorId: string, vector: number[], payload: Record<string, any>): Promise<void>;
|
|
736
|
+
delete(vectorId: string): Promise<void>;
|
|
737
|
+
deleteCol(): Promise<void>;
|
|
738
|
+
list(filters?: SearchFilters, limit?: number): Promise<[VectorStoreResult[], number]>;
|
|
739
|
+
private generateUUID;
|
|
740
|
+
getUserId(): Promise<string>;
|
|
741
|
+
setUserId(userId: string): Promise<void>;
|
|
742
|
+
initialize(): Promise<void>;
|
|
743
|
+
}
|
|
744
|
+
|
|
707
745
|
interface HistoryManager {
|
|
708
746
|
addHistory(memoryId: string, previousValue: string | null, newValue: string | null, action: string, createdAt?: string, updatedAt?: string, isDeleted?: number): Promise<void>;
|
|
709
747
|
getHistory(memoryId: string): Promise<any[]>;
|
|
@@ -724,4 +762,4 @@ declare class HistoryManagerFactory {
|
|
|
724
762
|
static create(provider: string, config: HistoryStoreConfig): HistoryManager;
|
|
725
763
|
}
|
|
726
764
|
|
|
727
|
-
export { type AddMemoryOptions, AnthropicLLM, AzureOpenAIEmbedder, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, GoogleEmbedder, GoogleLLM, type GraphStoreConfig, GroqLLM, HistoryManagerFactory, type HistoryStoreConfig, type LLM, type LLMConfig, LLMFactory, type LLMResponse, LangchainEmbedder, LangchainLLM, LangchainVectorStore, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, MistralLLM, type MultiModalMessages, type Neo4jConfig, OllamaEmbedder, OllamaLLM, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, SupabaseDB, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
|
765
|
+
export { type AddMemoryOptions, AnthropicLLM, AzureOpenAIEmbedder, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, GoogleEmbedder, GoogleLLM, type GraphStoreConfig, GroqLLM, HistoryManagerFactory, type HistoryStoreConfig, type LLM, type LLMConfig, LLMFactory, type LLMResponse, LangchainEmbedder, LangchainLLM, LangchainVectorStore, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, MistralLLM, type MultiModalMessages, type Neo4jConfig, OllamaEmbedder, OllamaLLM, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, SupabaseDB, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult, VectorizeDB };
|
package/dist/oss/index.d.ts
CHANGED
|
@@ -106,14 +106,17 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
106
106
|
modelProperties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
107
107
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
108
108
|
model: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodAny]>>;
|
|
109
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
109
110
|
}, "strip", z.ZodTypeAny, {
|
|
110
111
|
modelProperties?: Record<string, any> | undefined;
|
|
111
112
|
apiKey?: string | undefined;
|
|
112
113
|
model?: any;
|
|
114
|
+
baseURL?: string | undefined;
|
|
113
115
|
}, {
|
|
114
116
|
modelProperties?: Record<string, any> | undefined;
|
|
115
117
|
apiKey?: string | undefined;
|
|
116
118
|
model?: any;
|
|
119
|
+
baseURL?: string | undefined;
|
|
117
120
|
}>;
|
|
118
121
|
}, "strip", z.ZodTypeAny, {
|
|
119
122
|
provider: string;
|
|
@@ -121,6 +124,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
121
124
|
modelProperties?: Record<string, any> | undefined;
|
|
122
125
|
apiKey?: string | undefined;
|
|
123
126
|
model?: any;
|
|
127
|
+
baseURL?: string | undefined;
|
|
124
128
|
};
|
|
125
129
|
}, {
|
|
126
130
|
provider: string;
|
|
@@ -128,6 +132,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
128
132
|
modelProperties?: Record<string, any> | undefined;
|
|
129
133
|
apiKey?: string | undefined;
|
|
130
134
|
model?: any;
|
|
135
|
+
baseURL?: string | undefined;
|
|
131
136
|
};
|
|
132
137
|
}>;
|
|
133
138
|
vectorStore: z.ZodObject<{
|
|
@@ -170,14 +175,17 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
170
175
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
171
176
|
model: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodAny]>>;
|
|
172
177
|
modelProperties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
178
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
173
179
|
}, "strip", z.ZodTypeAny, {
|
|
174
180
|
modelProperties?: Record<string, any> | undefined;
|
|
175
181
|
apiKey?: string | undefined;
|
|
176
182
|
model?: any;
|
|
183
|
+
baseURL?: string | undefined;
|
|
177
184
|
}, {
|
|
178
185
|
modelProperties?: Record<string, any> | undefined;
|
|
179
186
|
apiKey?: string | undefined;
|
|
180
187
|
model?: any;
|
|
188
|
+
baseURL?: string | undefined;
|
|
181
189
|
}>;
|
|
182
190
|
}, "strip", z.ZodTypeAny, {
|
|
183
191
|
provider: string;
|
|
@@ -185,6 +193,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
185
193
|
modelProperties?: Record<string, any> | undefined;
|
|
186
194
|
apiKey?: string | undefined;
|
|
187
195
|
model?: any;
|
|
196
|
+
baseURL?: string | undefined;
|
|
188
197
|
};
|
|
189
198
|
}, {
|
|
190
199
|
provider: string;
|
|
@@ -192,6 +201,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
192
201
|
modelProperties?: Record<string, any> | undefined;
|
|
193
202
|
apiKey?: string | undefined;
|
|
194
203
|
model?: any;
|
|
204
|
+
baseURL?: string | undefined;
|
|
195
205
|
};
|
|
196
206
|
}>;
|
|
197
207
|
historyDbPath: z.ZodOptional<z.ZodString>;
|
|
@@ -266,6 +276,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
266
276
|
modelProperties?: Record<string, any> | undefined;
|
|
267
277
|
apiKey?: string | undefined;
|
|
268
278
|
model?: any;
|
|
279
|
+
baseURL?: string | undefined;
|
|
269
280
|
};
|
|
270
281
|
};
|
|
271
282
|
vectorStore: {
|
|
@@ -284,6 +295,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
284
295
|
modelProperties?: Record<string, any> | undefined;
|
|
285
296
|
apiKey?: string | undefined;
|
|
286
297
|
model?: any;
|
|
298
|
+
baseURL?: string | undefined;
|
|
287
299
|
};
|
|
288
300
|
};
|
|
289
301
|
version?: string | undefined;
|
|
@@ -315,6 +327,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
315
327
|
modelProperties?: Record<string, any> | undefined;
|
|
316
328
|
apiKey?: string | undefined;
|
|
317
329
|
model?: any;
|
|
330
|
+
baseURL?: string | undefined;
|
|
318
331
|
};
|
|
319
332
|
};
|
|
320
333
|
vectorStore: {
|
|
@@ -333,6 +346,7 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
333
346
|
modelProperties?: Record<string, any> | undefined;
|
|
334
347
|
apiKey?: string | undefined;
|
|
335
348
|
model?: any;
|
|
349
|
+
baseURL?: string | undefined;
|
|
336
350
|
};
|
|
337
351
|
};
|
|
338
352
|
version?: string | undefined;
|
|
@@ -704,6 +718,30 @@ declare class LangchainVectorStore implements VectorStore {
|
|
|
704
718
|
initialize(): Promise<void>;
|
|
705
719
|
}
|
|
706
720
|
|
|
721
|
+
interface VectorizeConfig extends VectorStoreConfig {
|
|
722
|
+
apiKey?: string;
|
|
723
|
+
indexName: string;
|
|
724
|
+
accountId: string;
|
|
725
|
+
}
|
|
726
|
+
declare class VectorizeDB implements VectorStore {
|
|
727
|
+
private client;
|
|
728
|
+
private dimensions;
|
|
729
|
+
private indexName;
|
|
730
|
+
private accountId;
|
|
731
|
+
constructor(config: VectorizeConfig);
|
|
732
|
+
insert(vectors: number[][], ids: string[], payloads: Record<string, any>[]): Promise<void>;
|
|
733
|
+
search(query: number[], limit?: number, filters?: SearchFilters): Promise<VectorStoreResult[]>;
|
|
734
|
+
get(vectorId: string): Promise<VectorStoreResult | null>;
|
|
735
|
+
update(vectorId: string, vector: number[], payload: Record<string, any>): Promise<void>;
|
|
736
|
+
delete(vectorId: string): Promise<void>;
|
|
737
|
+
deleteCol(): Promise<void>;
|
|
738
|
+
list(filters?: SearchFilters, limit?: number): Promise<[VectorStoreResult[], number]>;
|
|
739
|
+
private generateUUID;
|
|
740
|
+
getUserId(): Promise<string>;
|
|
741
|
+
setUserId(userId: string): Promise<void>;
|
|
742
|
+
initialize(): Promise<void>;
|
|
743
|
+
}
|
|
744
|
+
|
|
707
745
|
interface HistoryManager {
|
|
708
746
|
addHistory(memoryId: string, previousValue: string | null, newValue: string | null, action: string, createdAt?: string, updatedAt?: string, isDeleted?: number): Promise<void>;
|
|
709
747
|
getHistory(memoryId: string): Promise<any[]>;
|
|
@@ -724,4 +762,4 @@ declare class HistoryManagerFactory {
|
|
|
724
762
|
static create(provider: string, config: HistoryStoreConfig): HistoryManager;
|
|
725
763
|
}
|
|
726
764
|
|
|
727
|
-
export { type AddMemoryOptions, AnthropicLLM, AzureOpenAIEmbedder, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, GoogleEmbedder, GoogleLLM, type GraphStoreConfig, GroqLLM, HistoryManagerFactory, type HistoryStoreConfig, type LLM, type LLMConfig, LLMFactory, type LLMResponse, LangchainEmbedder, LangchainLLM, LangchainVectorStore, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, MistralLLM, type MultiModalMessages, type Neo4jConfig, OllamaEmbedder, OllamaLLM, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, SupabaseDB, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
|
765
|
+
export { type AddMemoryOptions, AnthropicLLM, AzureOpenAIEmbedder, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, GoogleEmbedder, GoogleLLM, type GraphStoreConfig, GroqLLM, HistoryManagerFactory, type HistoryStoreConfig, type LLM, type LLMConfig, LLMFactory, type LLMResponse, LangchainEmbedder, LangchainLLM, LangchainVectorStore, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, MistralLLM, type MultiModalMessages, type Neo4jConfig, OllamaEmbedder, OllamaLLM, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, SupabaseDB, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult, VectorizeDB };
|
package/dist/oss/index.js
CHANGED
|
@@ -53,7 +53,8 @@ __export(index_exports, {
|
|
|
53
53
|
Qdrant: () => Qdrant,
|
|
54
54
|
RedisDB: () => RedisDB,
|
|
55
55
|
SupabaseDB: () => SupabaseDB,
|
|
56
|
-
VectorStoreFactory: () => VectorStoreFactory
|
|
56
|
+
VectorStoreFactory: () => VectorStoreFactory,
|
|
57
|
+
VectorizeDB: () => VectorizeDB
|
|
57
58
|
});
|
|
58
59
|
module.exports = __toCommonJS(index_exports);
|
|
59
60
|
|
|
@@ -70,7 +71,8 @@ var MemoryConfigSchema = import_zod.z.object({
|
|
|
70
71
|
config: import_zod.z.object({
|
|
71
72
|
modelProperties: import_zod.z.record(import_zod.z.string(), import_zod.z.any()).optional(),
|
|
72
73
|
apiKey: import_zod.z.string().optional(),
|
|
73
|
-
model: import_zod.z.union([import_zod.z.string(), import_zod.z.any()]).optional()
|
|
74
|
+
model: import_zod.z.union([import_zod.z.string(), import_zod.z.any()]).optional(),
|
|
75
|
+
baseURL: import_zod.z.string().optional()
|
|
74
76
|
})
|
|
75
77
|
}),
|
|
76
78
|
vectorStore: import_zod.z.object({
|
|
@@ -86,7 +88,8 @@ var MemoryConfigSchema = import_zod.z.object({
|
|
|
86
88
|
config: import_zod.z.object({
|
|
87
89
|
apiKey: import_zod.z.string().optional(),
|
|
88
90
|
model: import_zod.z.union([import_zod.z.string(), import_zod.z.any()]).optional(),
|
|
89
|
-
modelProperties: import_zod.z.record(import_zod.z.string(), import_zod.z.any()).optional()
|
|
91
|
+
modelProperties: import_zod.z.record(import_zod.z.string(), import_zod.z.any()).optional(),
|
|
92
|
+
baseURL: import_zod.z.string().optional()
|
|
90
93
|
})
|
|
91
94
|
}),
|
|
92
95
|
historyDbPath: import_zod.z.string().optional(),
|
|
@@ -892,6 +895,377 @@ var Qdrant = class {
|
|
|
892
895
|
}
|
|
893
896
|
};
|
|
894
897
|
|
|
898
|
+
// src/oss/src/vector_stores/vectorize.ts
|
|
899
|
+
var import_cloudflare = __toESM(require("cloudflare"));
|
|
900
|
+
var VectorizeDB = class {
|
|
901
|
+
constructor(config) {
|
|
902
|
+
this.client = null;
|
|
903
|
+
this.client = new import_cloudflare.default({ apiToken: config.apiKey });
|
|
904
|
+
this.dimensions = config.dimension || 1536;
|
|
905
|
+
this.indexName = config.indexName;
|
|
906
|
+
this.accountId = config.accountId;
|
|
907
|
+
this.initialize().catch(console.error);
|
|
908
|
+
}
|
|
909
|
+
async insert(vectors, ids, payloads) {
|
|
910
|
+
var _a2;
|
|
911
|
+
try {
|
|
912
|
+
const vectorObjects = vectors.map(
|
|
913
|
+
(vector, index) => ({
|
|
914
|
+
id: ids[index],
|
|
915
|
+
values: vector,
|
|
916
|
+
metadata: payloads[index] || {}
|
|
917
|
+
})
|
|
918
|
+
);
|
|
919
|
+
const ndjsonPayload = vectorObjects.map((v) => JSON.stringify(v)).join("\n");
|
|
920
|
+
const response = await fetch(
|
|
921
|
+
`https://api.cloudflare.com/client/v4/accounts/${this.accountId}/vectorize/v2/indexes/${this.indexName}/insert`,
|
|
922
|
+
{
|
|
923
|
+
method: "POST",
|
|
924
|
+
headers: {
|
|
925
|
+
"Content-Type": "application/x-ndjson",
|
|
926
|
+
Authorization: `Bearer ${(_a2 = this.client) == null ? void 0 : _a2.apiToken}`
|
|
927
|
+
},
|
|
928
|
+
body: ndjsonPayload
|
|
929
|
+
}
|
|
930
|
+
);
|
|
931
|
+
if (!response.ok) {
|
|
932
|
+
const errorText = await response.text();
|
|
933
|
+
throw new Error(
|
|
934
|
+
`Failed to insert vectors: ${response.status} ${errorText}`
|
|
935
|
+
);
|
|
936
|
+
}
|
|
937
|
+
} catch (error) {
|
|
938
|
+
console.error("Error inserting vectors:", error);
|
|
939
|
+
throw new Error(
|
|
940
|
+
`Failed to insert vectors: ${error instanceof Error ? error.message : String(error)}`
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
async search(query, limit = 5, filters) {
|
|
945
|
+
var _a2, _b;
|
|
946
|
+
try {
|
|
947
|
+
const result = await ((_a2 = this.client) == null ? void 0 : _a2.vectorize.indexes.query(
|
|
948
|
+
this.indexName,
|
|
949
|
+
{
|
|
950
|
+
account_id: this.accountId,
|
|
951
|
+
vector: query,
|
|
952
|
+
filter: filters,
|
|
953
|
+
returnMetadata: "all",
|
|
954
|
+
topK: limit
|
|
955
|
+
}
|
|
956
|
+
));
|
|
957
|
+
return ((_b = result == null ? void 0 : result.matches) == null ? void 0 : _b.map((match) => ({
|
|
958
|
+
id: match.id,
|
|
959
|
+
payload: match.metadata,
|
|
960
|
+
score: match.score
|
|
961
|
+
}))) || [];
|
|
962
|
+
} catch (error) {
|
|
963
|
+
console.error("Error searching vectors:", error);
|
|
964
|
+
throw new Error(
|
|
965
|
+
`Failed to search vectors: ${error instanceof Error ? error.message : String(error)}`
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
async get(vectorId) {
|
|
970
|
+
var _a2;
|
|
971
|
+
try {
|
|
972
|
+
const result = await ((_a2 = this.client) == null ? void 0 : _a2.vectorize.indexes.getByIds(
|
|
973
|
+
this.indexName,
|
|
974
|
+
{
|
|
975
|
+
account_id: this.accountId,
|
|
976
|
+
ids: [vectorId]
|
|
977
|
+
}
|
|
978
|
+
));
|
|
979
|
+
if (!(result == null ? void 0 : result.length)) return null;
|
|
980
|
+
return {
|
|
981
|
+
id: vectorId,
|
|
982
|
+
payload: result[0].metadata
|
|
983
|
+
};
|
|
984
|
+
} catch (error) {
|
|
985
|
+
console.error("Error getting vector:", error);
|
|
986
|
+
throw new Error(
|
|
987
|
+
`Failed to get vector: ${error instanceof Error ? error.message : String(error)}`
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
async update(vectorId, vector, payload) {
|
|
992
|
+
var _a2;
|
|
993
|
+
try {
|
|
994
|
+
const data = {
|
|
995
|
+
id: vectorId,
|
|
996
|
+
values: vector,
|
|
997
|
+
metadata: payload
|
|
998
|
+
};
|
|
999
|
+
const response = await fetch(
|
|
1000
|
+
`https://api.cloudflare.com/client/v4/accounts/${this.accountId}/vectorize/v2/indexes/${this.indexName}/upsert`,
|
|
1001
|
+
{
|
|
1002
|
+
method: "POST",
|
|
1003
|
+
headers: {
|
|
1004
|
+
"Content-Type": "application/x-ndjson",
|
|
1005
|
+
Authorization: `Bearer ${(_a2 = this.client) == null ? void 0 : _a2.apiToken}`
|
|
1006
|
+
},
|
|
1007
|
+
body: JSON.stringify(data) + "\n"
|
|
1008
|
+
// ndjson format
|
|
1009
|
+
}
|
|
1010
|
+
);
|
|
1011
|
+
if (!response.ok) {
|
|
1012
|
+
const errorText = await response.text();
|
|
1013
|
+
throw new Error(
|
|
1014
|
+
`Failed to update vector: ${response.status} ${errorText}`
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
1017
|
+
} catch (error) {
|
|
1018
|
+
console.error("Error updating vector:", error);
|
|
1019
|
+
throw new Error(
|
|
1020
|
+
`Failed to update vector: ${error instanceof Error ? error.message : String(error)}`
|
|
1021
|
+
);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
async delete(vectorId) {
|
|
1025
|
+
var _a2;
|
|
1026
|
+
try {
|
|
1027
|
+
await ((_a2 = this.client) == null ? void 0 : _a2.vectorize.indexes.deleteByIds(this.indexName, {
|
|
1028
|
+
account_id: this.accountId,
|
|
1029
|
+
ids: [vectorId]
|
|
1030
|
+
}));
|
|
1031
|
+
} catch (error) {
|
|
1032
|
+
console.error("Error deleting vector:", error);
|
|
1033
|
+
throw new Error(
|
|
1034
|
+
`Failed to delete vector: ${error instanceof Error ? error.message : String(error)}`
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
async deleteCol() {
|
|
1039
|
+
var _a2;
|
|
1040
|
+
try {
|
|
1041
|
+
await ((_a2 = this.client) == null ? void 0 : _a2.vectorize.indexes.delete(this.indexName, {
|
|
1042
|
+
account_id: this.accountId
|
|
1043
|
+
}));
|
|
1044
|
+
} catch (error) {
|
|
1045
|
+
console.error("Error deleting collection:", error);
|
|
1046
|
+
throw new Error(
|
|
1047
|
+
`Failed to delete collection: ${error instanceof Error ? error.message : String(error)}`
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
async list(filters, limit = 20) {
|
|
1052
|
+
var _a2, _b;
|
|
1053
|
+
try {
|
|
1054
|
+
const result = await ((_a2 = this.client) == null ? void 0 : _a2.vectorize.indexes.query(
|
|
1055
|
+
this.indexName,
|
|
1056
|
+
{
|
|
1057
|
+
account_id: this.accountId,
|
|
1058
|
+
vector: Array(this.dimensions).fill(0),
|
|
1059
|
+
// Dummy vector for listing
|
|
1060
|
+
filter: filters,
|
|
1061
|
+
topK: limit,
|
|
1062
|
+
returnMetadata: "all"
|
|
1063
|
+
}
|
|
1064
|
+
));
|
|
1065
|
+
const matches = ((_b = result == null ? void 0 : result.matches) == null ? void 0 : _b.map((match) => ({
|
|
1066
|
+
id: match.id,
|
|
1067
|
+
payload: match.metadata,
|
|
1068
|
+
score: match.score
|
|
1069
|
+
}))) || [];
|
|
1070
|
+
return [matches, matches.length];
|
|
1071
|
+
} catch (error) {
|
|
1072
|
+
console.error("Error listing vectors:", error);
|
|
1073
|
+
throw new Error(
|
|
1074
|
+
`Failed to list vectors: ${error instanceof Error ? error.message : String(error)}`
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
generateUUID() {
|
|
1079
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
1080
|
+
/[xy]/g,
|
|
1081
|
+
function(c) {
|
|
1082
|
+
const r = Math.random() * 16 | 0;
|
|
1083
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
1084
|
+
return v.toString(16);
|
|
1085
|
+
}
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
async getUserId() {
|
|
1089
|
+
var _a2, _b, _c;
|
|
1090
|
+
try {
|
|
1091
|
+
let found = false;
|
|
1092
|
+
for await (const index of this.client.vectorize.indexes.list({
|
|
1093
|
+
account_id: this.accountId
|
|
1094
|
+
})) {
|
|
1095
|
+
if (index.name === "memory_migrations") {
|
|
1096
|
+
found = true;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
if (!found) {
|
|
1100
|
+
await ((_a2 = this.client) == null ? void 0 : _a2.vectorize.indexes.create({
|
|
1101
|
+
account_id: this.accountId,
|
|
1102
|
+
name: "memory_migrations",
|
|
1103
|
+
config: {
|
|
1104
|
+
dimensions: 1,
|
|
1105
|
+
metric: "cosine"
|
|
1106
|
+
}
|
|
1107
|
+
}));
|
|
1108
|
+
}
|
|
1109
|
+
const result = await ((_b = this.client) == null ? void 0 : _b.vectorize.indexes.query(
|
|
1110
|
+
"memory_migrations",
|
|
1111
|
+
{
|
|
1112
|
+
account_id: this.accountId,
|
|
1113
|
+
vector: [0],
|
|
1114
|
+
topK: 1,
|
|
1115
|
+
returnMetadata: "all"
|
|
1116
|
+
}
|
|
1117
|
+
));
|
|
1118
|
+
if (result.matches.length > 0) {
|
|
1119
|
+
return result.matches[0].metadata.userId;
|
|
1120
|
+
}
|
|
1121
|
+
const randomUserId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
1122
|
+
const data = {
|
|
1123
|
+
id: this.generateUUID(),
|
|
1124
|
+
values: [0],
|
|
1125
|
+
metadata: { userId: randomUserId }
|
|
1126
|
+
};
|
|
1127
|
+
await fetch(
|
|
1128
|
+
`https://api.cloudflare.com/client/v4/accounts/${this.accountId}/vectorize/v2/indexes/memory_migrations/upsert`,
|
|
1129
|
+
{
|
|
1130
|
+
method: "POST",
|
|
1131
|
+
headers: {
|
|
1132
|
+
"Content-Type": "application/x-ndjson",
|
|
1133
|
+
Authorization: `Bearer ${(_c = this.client) == null ? void 0 : _c.apiToken}`
|
|
1134
|
+
},
|
|
1135
|
+
body: JSON.stringify(data) + "\n"
|
|
1136
|
+
// ndjson format
|
|
1137
|
+
}
|
|
1138
|
+
);
|
|
1139
|
+
return randomUserId;
|
|
1140
|
+
} catch (error) {
|
|
1141
|
+
console.error("Error getting user ID:", error);
|
|
1142
|
+
throw new Error(
|
|
1143
|
+
`Failed to get user ID: ${error instanceof Error ? error.message : String(error)}`
|
|
1144
|
+
);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
async setUserId(userId) {
|
|
1148
|
+
var _a2, _b;
|
|
1149
|
+
try {
|
|
1150
|
+
const result = await ((_a2 = this.client) == null ? void 0 : _a2.vectorize.indexes.query(
|
|
1151
|
+
"memory_migrations",
|
|
1152
|
+
{
|
|
1153
|
+
account_id: this.accountId,
|
|
1154
|
+
vector: [0],
|
|
1155
|
+
topK: 1,
|
|
1156
|
+
returnMetadata: "all"
|
|
1157
|
+
}
|
|
1158
|
+
));
|
|
1159
|
+
const pointId = result.matches.length > 0 ? result.matches[0].id : this.generateUUID();
|
|
1160
|
+
const data = {
|
|
1161
|
+
id: pointId,
|
|
1162
|
+
values: [0],
|
|
1163
|
+
metadata: { userId }
|
|
1164
|
+
};
|
|
1165
|
+
await fetch(
|
|
1166
|
+
`https://api.cloudflare.com/client/v4/accounts/${this.accountId}/vectorize/v2/indexes/memory_migrations/upsert`,
|
|
1167
|
+
{
|
|
1168
|
+
method: "POST",
|
|
1169
|
+
headers: {
|
|
1170
|
+
"Content-Type": "application/x-ndjson",
|
|
1171
|
+
Authorization: `Bearer ${(_b = this.client) == null ? void 0 : _b.apiToken}`
|
|
1172
|
+
},
|
|
1173
|
+
body: JSON.stringify(data) + "\n"
|
|
1174
|
+
// ndjson format
|
|
1175
|
+
}
|
|
1176
|
+
);
|
|
1177
|
+
} catch (error) {
|
|
1178
|
+
console.error("Error setting user ID:", error);
|
|
1179
|
+
throw new Error(
|
|
1180
|
+
`Failed to set user ID: ${error instanceof Error ? error.message : String(error)}`
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
async initialize() {
|
|
1185
|
+
var _a2, _b, _c, _d, _e;
|
|
1186
|
+
try {
|
|
1187
|
+
let indexFound = false;
|
|
1188
|
+
for await (const idx of this.client.vectorize.indexes.list({
|
|
1189
|
+
account_id: this.accountId
|
|
1190
|
+
})) {
|
|
1191
|
+
if (idx.name === this.indexName) {
|
|
1192
|
+
indexFound = true;
|
|
1193
|
+
break;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
if (!indexFound) {
|
|
1197
|
+
try {
|
|
1198
|
+
await ((_a2 = this.client) == null ? void 0 : _a2.vectorize.indexes.create({
|
|
1199
|
+
account_id: this.accountId,
|
|
1200
|
+
name: this.indexName,
|
|
1201
|
+
config: {
|
|
1202
|
+
dimensions: this.dimensions,
|
|
1203
|
+
metric: "cosine"
|
|
1204
|
+
}
|
|
1205
|
+
}));
|
|
1206
|
+
const properties2 = ["userId", "agentId", "runId"];
|
|
1207
|
+
for (const propertyName of properties2) {
|
|
1208
|
+
await ((_b = this.client) == null ? void 0 : _b.vectorize.indexes.metadataIndex.create(
|
|
1209
|
+
this.indexName,
|
|
1210
|
+
{
|
|
1211
|
+
account_id: this.accountId,
|
|
1212
|
+
indexType: "string",
|
|
1213
|
+
propertyName
|
|
1214
|
+
}
|
|
1215
|
+
));
|
|
1216
|
+
}
|
|
1217
|
+
} catch (err) {
|
|
1218
|
+
throw new Error(err);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
const metadataIndexes = await ((_c = this.client) == null ? void 0 : _c.vectorize.indexes.metadataIndex.list(
|
|
1222
|
+
this.indexName,
|
|
1223
|
+
{
|
|
1224
|
+
account_id: this.accountId
|
|
1225
|
+
}
|
|
1226
|
+
));
|
|
1227
|
+
const existingMetadataIndexes = /* @__PURE__ */ new Set();
|
|
1228
|
+
for (const metadataIndex of (metadataIndexes == null ? void 0 : metadataIndexes.metadataIndexes) || []) {
|
|
1229
|
+
existingMetadataIndexes.add(metadataIndex.propertyName);
|
|
1230
|
+
}
|
|
1231
|
+
const properties = ["userId", "agentId", "runId"];
|
|
1232
|
+
for (const propertyName of properties) {
|
|
1233
|
+
if (!existingMetadataIndexes.has(propertyName)) {
|
|
1234
|
+
await ((_d = this.client) == null ? void 0 : _d.vectorize.indexes.metadataIndex.create(
|
|
1235
|
+
this.indexName,
|
|
1236
|
+
{
|
|
1237
|
+
account_id: this.accountId,
|
|
1238
|
+
indexType: "string",
|
|
1239
|
+
propertyName
|
|
1240
|
+
}
|
|
1241
|
+
));
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
let found = false;
|
|
1245
|
+
for await (const index of this.client.vectorize.indexes.list({
|
|
1246
|
+
account_id: this.accountId
|
|
1247
|
+
})) {
|
|
1248
|
+
if (index.name === "memory_migrations") {
|
|
1249
|
+
found = true;
|
|
1250
|
+
break;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
if (!found) {
|
|
1254
|
+
await ((_e = this.client) == null ? void 0 : _e.vectorize.indexes.create({
|
|
1255
|
+
account_id: this.accountId,
|
|
1256
|
+
name: "memory_migrations",
|
|
1257
|
+
config: {
|
|
1258
|
+
dimensions: 1,
|
|
1259
|
+
metric: "cosine"
|
|
1260
|
+
}
|
|
1261
|
+
}));
|
|
1262
|
+
}
|
|
1263
|
+
} catch (err) {
|
|
1264
|
+
throw new Error(err);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
|
|
895
1269
|
// src/oss/src/vector_stores/redis.ts
|
|
896
1270
|
var import_redis = require("redis");
|
|
897
1271
|
var DEFAULT_FIELDS = [
|
|
@@ -2797,6 +3171,8 @@ var VectorStoreFactory = class {
|
|
|
2797
3171
|
return new SupabaseDB(config);
|
|
2798
3172
|
case "langchain":
|
|
2799
3173
|
return new LangchainVectorStore(config);
|
|
3174
|
+
case "vectorize":
|
|
3175
|
+
return new VectorizeDB(config);
|
|
2800
3176
|
default:
|
|
2801
3177
|
throw new Error(`Unsupported vector store provider: ${provider}`);
|
|
2802
3178
|
}
|
|
@@ -4263,6 +4639,7 @@ ${parsedMessages}`] : getFactRetrievalMessages(parsedMessages);
|
|
|
4263
4639
|
Qdrant,
|
|
4264
4640
|
RedisDB,
|
|
4265
4641
|
SupabaseDB,
|
|
4266
|
-
VectorStoreFactory
|
|
4642
|
+
VectorStoreFactory,
|
|
4643
|
+
VectorizeDB
|
|
4267
4644
|
});
|
|
4268
4645
|
//# sourceMappingURL=index.js.map
|