@vectorstores/azure 0.1.0
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/LICENSE +21 -0
- package/dist/index.cjs +1656 -0
- package/dist/index.d.cts +585 -0
- package/dist/index.d.ts +585 -0
- package/dist/index.edge-light.d.ts +585 -0
- package/dist/index.edge-light.js +1636 -0
- package/dist/index.js +1636 -0
- package/dist/storage.cjs +458 -0
- package/dist/storage.d.cts +220 -0
- package/dist/storage.d.ts +220 -0
- package/dist/storage.edge-light.d.ts +220 -0
- package/dist/storage.edge-light.js +451 -0
- package/dist/storage.js +451 -0
- package/package.json +77 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { BaseKVStore, KVDocumentStore, KVIndexStore } from '@vectorstores/core';
|
|
2
|
+
import { MongoClient } from 'mongodb';
|
|
3
|
+
import { CosmosClient } from '@azure/cosmos';
|
|
4
|
+
import { DefaultAzureCredential } from '@azure/identity';
|
|
5
|
+
import { getEnv } from '@vectorstores/env';
|
|
6
|
+
|
|
7
|
+
var version = "0.1.0";
|
|
8
|
+
var pkg = {
|
|
9
|
+
version: version};
|
|
10
|
+
|
|
11
|
+
const DEFAULT_CHAT_DATABASE$1 = "KVStoreDB";
|
|
12
|
+
const DEFAULT_CHAT_Collection = "KVStoreCollection";
|
|
13
|
+
class AzureCosmosVCoreKVStore extends BaseKVStore {
|
|
14
|
+
/**
|
|
15
|
+
* Create a new AzureCosmosDBNoSQLVectorStore instance.
|
|
16
|
+
*/ constructor({ mongoClient, dbName = DEFAULT_CHAT_DATABASE$1, collectionName = DEFAULT_CHAT_Collection }){
|
|
17
|
+
super();
|
|
18
|
+
if (!mongoClient) {
|
|
19
|
+
throw new Error("MongoClient is required for AzureCosmosDBNoSQLVectorStore initialization");
|
|
20
|
+
}
|
|
21
|
+
mongoClient.appendMetadata({
|
|
22
|
+
name: "VECTORSTORES_AZURE_COSMOS_VCORE_KV_STORE",
|
|
23
|
+
version: pkg.version
|
|
24
|
+
});
|
|
25
|
+
this.mongoClient = mongoClient;
|
|
26
|
+
this.dbName = dbName;
|
|
27
|
+
this.collectionName = collectionName;
|
|
28
|
+
}
|
|
29
|
+
client() {
|
|
30
|
+
return this.mongoClient;
|
|
31
|
+
}
|
|
32
|
+
async ensureCollection() {
|
|
33
|
+
if (!this.collection) {
|
|
34
|
+
this.collection = this.mongoClient.db(this.dbName).collection(this.collectionName);
|
|
35
|
+
}
|
|
36
|
+
return this.collection;
|
|
37
|
+
}
|
|
38
|
+
async put(key, val) {
|
|
39
|
+
const collection = await this.ensureCollection();
|
|
40
|
+
await collection.insertOne({
|
|
41
|
+
id: key,
|
|
42
|
+
messages: val
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async get(key) {
|
|
46
|
+
const collection = await this.ensureCollection();
|
|
47
|
+
const result = await collection.findOne({
|
|
48
|
+
id: key
|
|
49
|
+
});
|
|
50
|
+
return result || null;
|
|
51
|
+
}
|
|
52
|
+
async getAll() {
|
|
53
|
+
const collection = await this.ensureCollection();
|
|
54
|
+
const cursor = collection.find();
|
|
55
|
+
const output = {};
|
|
56
|
+
await cursor.forEach((item)=>{
|
|
57
|
+
output[item.id] = item.messages;
|
|
58
|
+
});
|
|
59
|
+
return output;
|
|
60
|
+
}
|
|
61
|
+
async delete(key) {
|
|
62
|
+
const collection = await this.ensureCollection();
|
|
63
|
+
await collection.deleteOne({
|
|
64
|
+
id: key
|
|
65
|
+
});
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const DEFAULT_DATABASE$3 = "DocumentStoreDB";
|
|
71
|
+
const DEFAULT_COLLECTION$1 = "DocumentStoreCollection";
|
|
72
|
+
class AzureCosmosVCoreDocumentStore extends KVDocumentStore {
|
|
73
|
+
constructor({ azureCosmosVCoreKVStore, namespace }){
|
|
74
|
+
super(azureCosmosVCoreKVStore, namespace);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Static method for creating an instance using a MongoClient.
|
|
78
|
+
* @returns Instance of AzureCosmosVCoreDocumentStore
|
|
79
|
+
* @param mongoClient - MongoClient instance
|
|
80
|
+
* @param dbName - Database name
|
|
81
|
+
* @param collectionName - Collection name
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const mongoClient = new MongoClient("mongodb://localhost:27017");
|
|
85
|
+
* const indexStore = AzureCosmosVCoreDocumentStore.fromMongoClient(mongoClient, "my_db", "my_collection");
|
|
86
|
+
* ```
|
|
87
|
+
*/ static fromMongoClient(mongoClient, dbName = DEFAULT_DATABASE$3, collectionName = DEFAULT_COLLECTION$1) {
|
|
88
|
+
const azureCosmosVCoreKVStore = new AzureCosmosVCoreKVStore({
|
|
89
|
+
mongoClient,
|
|
90
|
+
dbName,
|
|
91
|
+
collectionName
|
|
92
|
+
});
|
|
93
|
+
const namespace = `${dbName}.${collectionName}`;
|
|
94
|
+
return new AzureCosmosVCoreDocumentStore({
|
|
95
|
+
azureCosmosVCoreKVStore,
|
|
96
|
+
namespace
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Static method for creating an instance using a connection string.
|
|
101
|
+
* @returns Instance of AzureCosmosVCoreDocumentStore
|
|
102
|
+
* @param connectionString - MongoDB connection string
|
|
103
|
+
* @param dbName - Database name
|
|
104
|
+
* @param collectionName - Collection name
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const indexStore = AzureCosmosVCoreDocumentStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
|
|
108
|
+
* ```
|
|
109
|
+
*/ static fromConnectionString(connectionString, dbName = DEFAULT_DATABASE$3, collectionName = DEFAULT_COLLECTION$1) {
|
|
110
|
+
const mongoClient = new MongoClient(connectionString, {
|
|
111
|
+
appName: "VECTORSTORES_JS"
|
|
112
|
+
});
|
|
113
|
+
return new AzureCosmosVCoreDocumentStore({
|
|
114
|
+
azureCosmosVCoreKVStore: new AzureCosmosVCoreKVStore({
|
|
115
|
+
mongoClient,
|
|
116
|
+
dbName,
|
|
117
|
+
collectionName
|
|
118
|
+
}),
|
|
119
|
+
namespace: `${dbName}.${collectionName}`
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const USER_AGENT_SUFFIX = "vectorstores-cdbnosql-kvstore-javascript";
|
|
125
|
+
const DEFAULT_CHAT_DATABASE = "KVStoreDB";
|
|
126
|
+
const DEFAULT_CHAT_CONTAINER = "KVStoreContainer";
|
|
127
|
+
const DEFAULT_OFFER_THROUGHPUT = 400;
|
|
128
|
+
function parseConnectionString(connectionString) {
|
|
129
|
+
const parts = connectionString.split(";");
|
|
130
|
+
let endpoint = "";
|
|
131
|
+
let accountKey = "";
|
|
132
|
+
parts.forEach((part)=>{
|
|
133
|
+
const [key, value] = part.split("=");
|
|
134
|
+
if (key && key.trim() === "AccountEndpoint") {
|
|
135
|
+
endpoint = value?.trim() ?? "";
|
|
136
|
+
} else if ((key ?? "").trim() === "AccountKey") {
|
|
137
|
+
accountKey = value?.trim() ?? "";
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (!endpoint || !accountKey) {
|
|
141
|
+
throw new Error("Invalid connection string: missing AccountEndpoint or AccountKey.");
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
endpoint,
|
|
145
|
+
key: accountKey
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
class AzureCosmosNoSqlKVStore extends BaseKVStore {
|
|
149
|
+
constructor({ cosmosClient, dbName = DEFAULT_CHAT_DATABASE, containerName = DEFAULT_CHAT_CONTAINER, cosmosContainerProperties = {
|
|
150
|
+
partitionKey: "/id"
|
|
151
|
+
}, cosmosDatabaseProperties = {} }){
|
|
152
|
+
super();
|
|
153
|
+
if (!cosmosClient) {
|
|
154
|
+
throw new Error("CosmosClient is required for AzureCosmosDBNoSQLKVStore initialization");
|
|
155
|
+
}
|
|
156
|
+
this.cosmosClient = cosmosClient;
|
|
157
|
+
this.dbName = dbName;
|
|
158
|
+
this.containerName = containerName;
|
|
159
|
+
this.cosmosContainerProperties = cosmosContainerProperties;
|
|
160
|
+
this.cosmosDatabaseProperties = cosmosDatabaseProperties;
|
|
161
|
+
this.initialize = ()=>{
|
|
162
|
+
if (this.initPromise === undefined) {
|
|
163
|
+
this.initPromise = this.init().catch((error)=>{
|
|
164
|
+
console.error("Error during AzureCosmosDBNoSQLKVStore initialization", error);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return this.initPromise;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
client() {
|
|
171
|
+
return this.cosmosClient;
|
|
172
|
+
}
|
|
173
|
+
// Asynchronous initialization method to create database and container
|
|
174
|
+
async init() {
|
|
175
|
+
// Set default throughput if not provided
|
|
176
|
+
const throughput = this.cosmosDatabaseProperties?.throughput || DEFAULT_OFFER_THROUGHPUT;
|
|
177
|
+
// Create the database if it doesn't exist
|
|
178
|
+
const { database } = await this.cosmosClient.databases.createIfNotExists({
|
|
179
|
+
id: this.dbName,
|
|
180
|
+
throughput
|
|
181
|
+
});
|
|
182
|
+
this.database = database;
|
|
183
|
+
// Create the container if it doesn't exist
|
|
184
|
+
const { container } = await this.database.containers.createIfNotExists({
|
|
185
|
+
id: this.containerName,
|
|
186
|
+
throughput: this.cosmosContainerProperties?.throughput,
|
|
187
|
+
partitionKey: this.cosmosContainerProperties?.partitionKey,
|
|
188
|
+
indexingPolicy: this.cosmosContainerProperties?.indexingPolicy,
|
|
189
|
+
defaultTtl: this.cosmosContainerProperties?.defaultTtl,
|
|
190
|
+
uniqueKeyPolicy: this.cosmosContainerProperties?.uniqueKeyPolicy,
|
|
191
|
+
conflictResolutionPolicy: this.cosmosContainerProperties?.conflictResolutionPolicy,
|
|
192
|
+
computedProperties: this.cosmosContainerProperties?.computedProperties
|
|
193
|
+
});
|
|
194
|
+
this.container = container;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Static method for creating an instance using a connection string.
|
|
198
|
+
* If no connection string is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_CONNECTION_STRING` as connection string.
|
|
199
|
+
* @returns Instance of AzureCosmosNoSqlKVStore
|
|
200
|
+
*/ static fromConnectionString(config = {}) {
|
|
201
|
+
const cosmosConnectionString = config.connectionString || getEnv("AZURE_COSMOSDB_NOSQL_CONNECTION_STRING");
|
|
202
|
+
if (!cosmosConnectionString) {
|
|
203
|
+
throw new Error("Azure CosmosDB connection string must be provided");
|
|
204
|
+
}
|
|
205
|
+
const { endpoint, key } = parseConnectionString(cosmosConnectionString);
|
|
206
|
+
const cosmosClient = new CosmosClient({
|
|
207
|
+
endpoint,
|
|
208
|
+
key,
|
|
209
|
+
userAgentSuffix: USER_AGENT_SUFFIX
|
|
210
|
+
});
|
|
211
|
+
return new AzureCosmosNoSqlKVStore({
|
|
212
|
+
...config,
|
|
213
|
+
cosmosClient
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Static method for creating an instance using a account endpoint and key.
|
|
218
|
+
* If no endpoint and key is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as enpoint and `AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY` as key.
|
|
219
|
+
* @returns Instance of AzureCosmosNoSqlKVStore
|
|
220
|
+
*/ static fromAccountAndKey(config = {}) {
|
|
221
|
+
const cosmosEndpoint = config.endpoint || getEnv("AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT");
|
|
222
|
+
const cosmosKey = config.key || getEnv("AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY");
|
|
223
|
+
if (!cosmosEndpoint || !cosmosKey) {
|
|
224
|
+
throw new Error("Azure CosmosDB account endpoint and key must be provided");
|
|
225
|
+
}
|
|
226
|
+
const cosmosClient = new CosmosClient({
|
|
227
|
+
endpoint: cosmosEndpoint,
|
|
228
|
+
key: cosmosKey,
|
|
229
|
+
userAgentSuffix: USER_AGENT_SUFFIX
|
|
230
|
+
});
|
|
231
|
+
return new AzureCosmosNoSqlKVStore({
|
|
232
|
+
...config,
|
|
233
|
+
cosmosClient
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Static method for creating an instance using AAD token.
|
|
238
|
+
* If no endpoint and credentials are provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as endpoint and use DefaultAzureCredential() as credentials.
|
|
239
|
+
* @returns Instance of AzureCosmosNoSqlKVStore
|
|
240
|
+
*/ static fromAadToken(config = {}) {
|
|
241
|
+
const cosmosEndpoint = config.endpoint || getEnv("AZURE_COSMOSDB_NOSQL_CONNECTION_STRING");
|
|
242
|
+
if (!cosmosEndpoint) {
|
|
243
|
+
throw new Error("Azure CosmosDB account endpoint must be provided");
|
|
244
|
+
}
|
|
245
|
+
const credentials = config.credential ?? new DefaultAzureCredential();
|
|
246
|
+
const cosmosClient = new CosmosClient({
|
|
247
|
+
endpoint: cosmosEndpoint,
|
|
248
|
+
aadCredentials: credentials,
|
|
249
|
+
userAgentSuffix: USER_AGENT_SUFFIX
|
|
250
|
+
});
|
|
251
|
+
return new AzureCosmosNoSqlKVStore({
|
|
252
|
+
...config,
|
|
253
|
+
cosmosClient
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
async put(key, val) {
|
|
257
|
+
await this.initialize();
|
|
258
|
+
await this.container.items.upsert({
|
|
259
|
+
id: key,
|
|
260
|
+
messages: val
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
async get(key) {
|
|
264
|
+
await this.initialize();
|
|
265
|
+
try {
|
|
266
|
+
const { resource } = await this.container.item(key).read();
|
|
267
|
+
return resource?.messages || null;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
console.error(`Error retrieving item with key ${key}:`, error);
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async getAll() {
|
|
274
|
+
await this.initialize();
|
|
275
|
+
const querySpec = {
|
|
276
|
+
query: "SELECT * from c"
|
|
277
|
+
};
|
|
278
|
+
const { resources } = await this.container.items.query(querySpec).fetchAll();
|
|
279
|
+
const output = resources.reduce((res, item)=>{
|
|
280
|
+
res[item.id] = item.messages;
|
|
281
|
+
return res;
|
|
282
|
+
}, {});
|
|
283
|
+
return output;
|
|
284
|
+
}
|
|
285
|
+
async delete(key) {
|
|
286
|
+
await this.initialize();
|
|
287
|
+
try {
|
|
288
|
+
await this.container.item(key).delete();
|
|
289
|
+
return true;
|
|
290
|
+
} catch (error) {
|
|
291
|
+
console.error(`Error deleting item with key ${key}:`, error);
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const DEFAULT_DATABASE$2 = "DocumentStoreDB";
|
|
298
|
+
const DEFAULT_CONTAINER$1 = "DocumentStoreContainer";
|
|
299
|
+
class AzureCosmosNoSqlDocumentStore extends KVDocumentStore {
|
|
300
|
+
constructor({ azureCosmosNoSqlKVStore, namespace }){
|
|
301
|
+
super(azureCosmosNoSqlKVStore, namespace);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Static method for creating an instance using a connection string.
|
|
305
|
+
* If no connection string is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_CONNECTION_STRING` as connection string.
|
|
306
|
+
* @returns Instance of AzureCosmosNoSqlDocumentStore
|
|
307
|
+
*/ static fromConnectionString(options = {}) {
|
|
308
|
+
options.dbName = options.dbName || DEFAULT_DATABASE$2;
|
|
309
|
+
options.containerName = options.containerName || DEFAULT_CONTAINER$1;
|
|
310
|
+
const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromConnectionString(options);
|
|
311
|
+
const namespace = `${options.dbName}.${options.containerName}`;
|
|
312
|
+
return new AzureCosmosNoSqlDocumentStore({
|
|
313
|
+
azureCosmosNoSqlKVStore,
|
|
314
|
+
namespace
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Static method for creating an instance using a account endpoint and key.
|
|
319
|
+
* If no endpoint and key is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as enpoint and `AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY` as key.
|
|
320
|
+
* @returns Instance of AzureCosmosNoSqlDocumentStore
|
|
321
|
+
*/ static fromAccountAndKey(options = {}) {
|
|
322
|
+
options.dbName = options.dbName || DEFAULT_DATABASE$2;
|
|
323
|
+
options.containerName = options.containerName || DEFAULT_CONTAINER$1;
|
|
324
|
+
const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromAccountAndKey(options);
|
|
325
|
+
const namespace = `${options.dbName}.${options.containerName}`;
|
|
326
|
+
return new AzureCosmosNoSqlDocumentStore({
|
|
327
|
+
azureCosmosNoSqlKVStore,
|
|
328
|
+
namespace
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Static method for creating an instance using AAD token.
|
|
333
|
+
* If no endpoint and credentials are provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as endpoint and use DefaultAzureCredential() as credentials.
|
|
334
|
+
* @returns Instance of AzureCosmosNoSqlDocumentStore
|
|
335
|
+
*/ static fromAadToken(options = {}) {
|
|
336
|
+
options.dbName = options.dbName || DEFAULT_DATABASE$2;
|
|
337
|
+
options.containerName = options.containerName || DEFAULT_CONTAINER$1;
|
|
338
|
+
const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromAadToken(options);
|
|
339
|
+
const namespace = `${options.dbName}.${options.containerName}`;
|
|
340
|
+
return new AzureCosmosNoSqlDocumentStore({
|
|
341
|
+
azureCosmosNoSqlKVStore,
|
|
342
|
+
namespace
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const DEFAULT_DATABASE$1 = "IndexStoreDB";
|
|
348
|
+
const DEFAULT_COLLECTION = "IndexStoreCollection";
|
|
349
|
+
class AzureCosmosVCoreIndexStore extends KVIndexStore {
|
|
350
|
+
constructor({ azureCosmosVCoreKVStore, namespace }){
|
|
351
|
+
super(azureCosmosVCoreKVStore, namespace);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Static method for creating an instance using a MongoClient.
|
|
355
|
+
* @returns Instance of AzureCosmosVCoreIndexStore
|
|
356
|
+
* @param mongoClient - MongoClient instance
|
|
357
|
+
* @param dbName - Database name
|
|
358
|
+
* @param collectionName - Collection name
|
|
359
|
+
* @example
|
|
360
|
+
* ```ts
|
|
361
|
+
* const mongoClient = new MongoClient("mongodb://localhost:27017");
|
|
362
|
+
* const indexStore = AzureCosmosVCoreIndexStore.fromMongoClient(mongoClient, "my_db", "my_collection");
|
|
363
|
+
* ```
|
|
364
|
+
*/ static fromMongoClient(mongoClient, dbName = DEFAULT_DATABASE$1, collectionName = DEFAULT_COLLECTION) {
|
|
365
|
+
const azureCosmosVCoreKVStore = new AzureCosmosVCoreKVStore({
|
|
366
|
+
mongoClient,
|
|
367
|
+
dbName,
|
|
368
|
+
collectionName
|
|
369
|
+
});
|
|
370
|
+
const namespace = `${dbName}.${collectionName}`;
|
|
371
|
+
return new AzureCosmosVCoreIndexStore({
|
|
372
|
+
azureCosmosVCoreKVStore,
|
|
373
|
+
namespace
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Static method for creating an instance using a connection string.
|
|
378
|
+
* @returns Instance of AzureCosmosVCoreIndexStore
|
|
379
|
+
* @param connectionString - MongoDB connection string
|
|
380
|
+
* @param dbName - Database name
|
|
381
|
+
* @param collectionName - Collection name
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* const indexStore = AzureCosmosVCoreIndexStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
|
|
385
|
+
* ```
|
|
386
|
+
*/ static fromConnectionString(connectionString, dbName = DEFAULT_DATABASE$1, collectionName = DEFAULT_COLLECTION) {
|
|
387
|
+
const mongoClient = new MongoClient(connectionString, {
|
|
388
|
+
appName: "VECTORSTORES_JS"
|
|
389
|
+
});
|
|
390
|
+
return new AzureCosmosVCoreIndexStore({
|
|
391
|
+
azureCosmosVCoreKVStore: new AzureCosmosVCoreKVStore({
|
|
392
|
+
mongoClient,
|
|
393
|
+
dbName,
|
|
394
|
+
collectionName
|
|
395
|
+
}),
|
|
396
|
+
namespace: `${dbName}.${collectionName}`
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const DEFAULT_DATABASE = "IndexStoreDB";
|
|
402
|
+
const DEFAULT_CONTAINER = "IndexStoreContainer";
|
|
403
|
+
class AzureCosmosNoSqlIndexStore extends KVIndexStore {
|
|
404
|
+
constructor({ azureCosmosNoSqlKVStore, namespace }){
|
|
405
|
+
super(azureCosmosNoSqlKVStore, namespace);
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Static method for creating an instance using a connection string.
|
|
409
|
+
* If no connection string is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_CONNECTION_STRING` as connection string.
|
|
410
|
+
* @returns Instance of AzureCosmosNoSqlIndexStore
|
|
411
|
+
*/ static fromConnectionString(options = {}) {
|
|
412
|
+
options.dbName = options.dbName || DEFAULT_DATABASE;
|
|
413
|
+
options.containerName = options.containerName || DEFAULT_CONTAINER;
|
|
414
|
+
const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromConnectionString(options);
|
|
415
|
+
const namespace = `${options.dbName}.${options.containerName}`;
|
|
416
|
+
return new AzureCosmosNoSqlIndexStore({
|
|
417
|
+
azureCosmosNoSqlKVStore,
|
|
418
|
+
namespace
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Static method for creating an instance using a account endpoint and key.
|
|
423
|
+
* If no endpoint and key is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as enpoint and `AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY` as key.
|
|
424
|
+
* @returns Instance of AzureCosmosNoSqlIndexStore
|
|
425
|
+
*/ static fromAccountAndKey(options = {}) {
|
|
426
|
+
options.dbName = options.dbName || DEFAULT_DATABASE;
|
|
427
|
+
options.containerName = options.containerName || DEFAULT_CONTAINER;
|
|
428
|
+
const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromAccountAndKey(options);
|
|
429
|
+
const namespace = `${options.dbName}.${options.containerName}`;
|
|
430
|
+
return new AzureCosmosNoSqlIndexStore({
|
|
431
|
+
azureCosmosNoSqlKVStore,
|
|
432
|
+
namespace
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Static method for creating an instance using AAD token.
|
|
437
|
+
* If no endpoint and credentials are provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as endpoint and use DefaultAzureCredential() as credentials.
|
|
438
|
+
* @returns Instance of AzureCosmosNoSqlIndexStore
|
|
439
|
+
*/ static fromAadToken(options = {}) {
|
|
440
|
+
options.dbName = options.dbName || DEFAULT_DATABASE;
|
|
441
|
+
options.containerName = options.containerName || DEFAULT_CONTAINER;
|
|
442
|
+
const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromAadToken(options);
|
|
443
|
+
const namespace = `${options.dbName}.${options.containerName}`;
|
|
444
|
+
return new AzureCosmosNoSqlIndexStore({
|
|
445
|
+
azureCosmosNoSqlKVStore,
|
|
446
|
+
namespace
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export { AzureCosmosNoSqlDocumentStore, AzureCosmosNoSqlIndexStore, AzureCosmosNoSqlKVStore, AzureCosmosVCoreDocumentStore, AzureCosmosVCoreIndexStore, AzureCosmosVCoreKVStore };
|