@vectorstores/mongodb 0.1.2 → 0.1.4
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/index.cjs +13 -61
- package/dist/index.d.cts +3 -35
- package/dist/index.d.ts +3 -35
- package/dist/index.edge-light.d.ts +3 -35
- package/dist/index.edge-light.js +15 -62
- package/dist/index.js +15 -62
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
3
|
var core = require('@vectorstores/core');
|
|
4
|
-
var mongodb = require('mongodb');
|
|
5
4
|
var env = require('@vectorstores/env');
|
|
6
|
-
|
|
7
|
-
var version = "0.1.2";
|
|
8
|
-
var pkg = {
|
|
9
|
-
version: version};
|
|
5
|
+
var mongodb = require('mongodb');
|
|
10
6
|
|
|
11
7
|
const DEFAULT_DB_NAME = "KVStoreDB";
|
|
12
8
|
const DEFAULT_COLLECTION_NAME = "KVStoreCollection";
|
|
@@ -75,61 +71,9 @@ class MongoKVStore extends core.BaseKVStore {
|
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
73
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
constructor({ mongoKVStore, namespace }){
|
|
82
|
-
super(mongoKVStore, namespace);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Static method for creating an instance using a MongoClient.
|
|
86
|
-
* @returns Instance of MongoDBDocumentStore
|
|
87
|
-
* @param mongoClient - MongoClient instance
|
|
88
|
-
* @param dbName - Database name
|
|
89
|
-
* @param collectionName - Collection name
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* const mongoClient = new MongoClient("mongodb://localhost:27017");
|
|
93
|
-
* const documentStore = MongoDBDocumentStore.fromMongoClient(mongoClient, "my_db", "my_collection");
|
|
94
|
-
* ```
|
|
95
|
-
*/ static fromMongoClient(mongoClient, dbName = DEFAULT_DATABASE, collectionName = DEFAULT_COLLECTION) {
|
|
96
|
-
const mongoKVStore = new MongoKVStore({
|
|
97
|
-
mongoClient,
|
|
98
|
-
dbName
|
|
99
|
-
});
|
|
100
|
-
mongoClient.appendMetadata({
|
|
101
|
-
name: "VECTORSTORES_MONGODB_DOC_STORE",
|
|
102
|
-
version: pkg.version
|
|
103
|
-
});
|
|
104
|
-
return new MongoDocumentStore({
|
|
105
|
-
mongoKVStore,
|
|
106
|
-
namespace: `${dbName}.${collectionName}`
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Static method for creating an instance using a connection string.
|
|
111
|
-
* @returns Instance of MongoDBDocumentStore
|
|
112
|
-
* @param connectionString - MongoDB connection string
|
|
113
|
-
* @param dbName - Database name
|
|
114
|
-
* @param collectionName - Collection name
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* const documentStore = MongoDBDocumentStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
|
|
118
|
-
* ```
|
|
119
|
-
*/ static fromConnectionString(connectionString, dbName = DEFAULT_DATABASE, collectionName = DEFAULT_COLLECTION) {
|
|
120
|
-
const mongoClient = new mongodb.MongoClient(connectionString, {
|
|
121
|
-
appName: "VECTORSTORES_JS"
|
|
122
|
-
});
|
|
123
|
-
const mongoKVStore = new MongoKVStore({
|
|
124
|
-
mongoClient,
|
|
125
|
-
dbName
|
|
126
|
-
});
|
|
127
|
-
return new MongoDocumentStore({
|
|
128
|
-
mongoKVStore,
|
|
129
|
-
namespace: `${dbName}.${collectionName}`
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
74
|
+
var version = "0.1.4";
|
|
75
|
+
var pkg = {
|
|
76
|
+
version: version};
|
|
133
77
|
|
|
134
78
|
// define your Atlas Search index. See detail https://www.mongodb.com/docs/atlas/atlas-search/field-types/knn-vector/
|
|
135
79
|
const DEFAULT_EMBEDDING_DEFINITION = {
|
|
@@ -335,6 +279,15 @@ function toMongoDBFilter(filters) {
|
|
|
335
279
|
};
|
|
336
280
|
return result;
|
|
337
281
|
}
|
|
282
|
+
async exists(refDocId) {
|
|
283
|
+
const collection = await this.ensureCollection();
|
|
284
|
+
const count = await collection.countDocuments({
|
|
285
|
+
[`${this.metadataKey}.ref_doc_id`]: refDocId
|
|
286
|
+
}, {
|
|
287
|
+
limit: 1
|
|
288
|
+
});
|
|
289
|
+
return count > 0;
|
|
290
|
+
}
|
|
338
291
|
}
|
|
339
292
|
|
|
340
293
|
/**
|
|
@@ -396,6 +349,5 @@ function toMongoDBFilter(filters) {
|
|
|
396
349
|
}
|
|
397
350
|
|
|
398
351
|
exports.MongoDBAtlasVectorSearch = MongoDBAtlasVectorSearch;
|
|
399
|
-
exports.MongoDocumentStore = MongoDocumentStore;
|
|
400
352
|
exports.MongoKVStore = MongoKVStore;
|
|
401
353
|
exports.SimpleMongoReader = SimpleMongoReader;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseKVStore, StoredValue,
|
|
1
|
+
import { BaseKVStore, StoredValue, BaseVectorStore, VectorStoreQuery, BaseEmbedding, VectorStoreBaseParams, BaseNode, VectorStoreQueryResult, BaseReader, Document } from '@vectorstores/core';
|
|
2
2
|
import { MongoClient, BulkWriteOptions, Collection, Document as Document$1, Filter } from 'mongodb';
|
|
3
3
|
|
|
4
4
|
interface MongoKVStoreConfig {
|
|
@@ -17,39 +17,6 @@ declare class MongoKVStore extends BaseKVStore {
|
|
|
17
17
|
delete(key: string, collectionName?: string): Promise<boolean>;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
interface MongoDBDocumentStoreConfig {
|
|
21
|
-
mongoKVStore: MongoKVStore;
|
|
22
|
-
namespace?: string;
|
|
23
|
-
}
|
|
24
|
-
declare class MongoDocumentStore extends KVDocumentStore {
|
|
25
|
-
constructor({ mongoKVStore, namespace }: MongoDBDocumentStoreConfig);
|
|
26
|
-
/**
|
|
27
|
-
* Static method for creating an instance using a MongoClient.
|
|
28
|
-
* @returns Instance of MongoDBDocumentStore
|
|
29
|
-
* @param mongoClient - MongoClient instance
|
|
30
|
-
* @param dbName - Database name
|
|
31
|
-
* @param collectionName - Collection name
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const mongoClient = new MongoClient("mongodb://localhost:27017");
|
|
35
|
-
* const documentStore = MongoDBDocumentStore.fromMongoClient(mongoClient, "my_db", "my_collection");
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
static fromMongoClient(mongoClient: MongoClient, dbName?: string, collectionName?: string): MongoDocumentStore;
|
|
39
|
-
/**
|
|
40
|
-
* Static method for creating an instance using a connection string.
|
|
41
|
-
* @returns Instance of MongoDBDocumentStore
|
|
42
|
-
* @param connectionString - MongoDB connection string
|
|
43
|
-
* @param dbName - Database name
|
|
44
|
-
* @param collectionName - Collection name
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* const documentStore = MongoDBDocumentStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
static fromConnectionString(connectionString: string, dbName?: string, collectionName?: string): MongoDocumentStore;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
20
|
/**
|
|
54
21
|
* Vector store that uses MongoDB Atlas for storage and vector search.
|
|
55
22
|
* This store uses the $vectorSearch aggregation stage to perform vector similarity search.
|
|
@@ -144,6 +111,7 @@ declare class MongoDBAtlasVectorSearch extends BaseVectorStore {
|
|
|
144
111
|
* @returns List of nodes and their similarities
|
|
145
112
|
*/
|
|
146
113
|
query(query: VectorStoreQuery, options?: object): Promise<VectorStoreQueryResult>;
|
|
114
|
+
exists(refDocId: string): Promise<boolean>;
|
|
147
115
|
}
|
|
148
116
|
|
|
149
117
|
/**
|
|
@@ -173,4 +141,4 @@ declare class SimpleMongoReader implements BaseReader<Document> {
|
|
|
173
141
|
loadData<TSchema extends Document$1 = Document$1>(dbName: string, collectionName: string, fieldNames?: string[], separator?: string, filterQuery?: Filter<TSchema>, maxDocs?: number, metadataNames?: string[]): Promise<Document[]>;
|
|
174
142
|
}
|
|
175
143
|
|
|
176
|
-
export { MongoDBAtlasVectorSearch,
|
|
144
|
+
export { MongoDBAtlasVectorSearch, MongoKVStore, SimpleMongoReader };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseKVStore, StoredValue,
|
|
1
|
+
import { BaseKVStore, StoredValue, BaseVectorStore, VectorStoreQuery, BaseEmbedding, VectorStoreBaseParams, BaseNode, VectorStoreQueryResult, BaseReader, Document } from '@vectorstores/core';
|
|
2
2
|
import { MongoClient, BulkWriteOptions, Collection, Document as Document$1, Filter } from 'mongodb';
|
|
3
3
|
|
|
4
4
|
interface MongoKVStoreConfig {
|
|
@@ -17,39 +17,6 @@ declare class MongoKVStore extends BaseKVStore {
|
|
|
17
17
|
delete(key: string, collectionName?: string): Promise<boolean>;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
interface MongoDBDocumentStoreConfig {
|
|
21
|
-
mongoKVStore: MongoKVStore;
|
|
22
|
-
namespace?: string;
|
|
23
|
-
}
|
|
24
|
-
declare class MongoDocumentStore extends KVDocumentStore {
|
|
25
|
-
constructor({ mongoKVStore, namespace }: MongoDBDocumentStoreConfig);
|
|
26
|
-
/**
|
|
27
|
-
* Static method for creating an instance using a MongoClient.
|
|
28
|
-
* @returns Instance of MongoDBDocumentStore
|
|
29
|
-
* @param mongoClient - MongoClient instance
|
|
30
|
-
* @param dbName - Database name
|
|
31
|
-
* @param collectionName - Collection name
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const mongoClient = new MongoClient("mongodb://localhost:27017");
|
|
35
|
-
* const documentStore = MongoDBDocumentStore.fromMongoClient(mongoClient, "my_db", "my_collection");
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
static fromMongoClient(mongoClient: MongoClient, dbName?: string, collectionName?: string): MongoDocumentStore;
|
|
39
|
-
/**
|
|
40
|
-
* Static method for creating an instance using a connection string.
|
|
41
|
-
* @returns Instance of MongoDBDocumentStore
|
|
42
|
-
* @param connectionString - MongoDB connection string
|
|
43
|
-
* @param dbName - Database name
|
|
44
|
-
* @param collectionName - Collection name
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* const documentStore = MongoDBDocumentStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
static fromConnectionString(connectionString: string, dbName?: string, collectionName?: string): MongoDocumentStore;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
20
|
/**
|
|
54
21
|
* Vector store that uses MongoDB Atlas for storage and vector search.
|
|
55
22
|
* This store uses the $vectorSearch aggregation stage to perform vector similarity search.
|
|
@@ -144,6 +111,7 @@ declare class MongoDBAtlasVectorSearch extends BaseVectorStore {
|
|
|
144
111
|
* @returns List of nodes and their similarities
|
|
145
112
|
*/
|
|
146
113
|
query(query: VectorStoreQuery, options?: object): Promise<VectorStoreQueryResult>;
|
|
114
|
+
exists(refDocId: string): Promise<boolean>;
|
|
147
115
|
}
|
|
148
116
|
|
|
149
117
|
/**
|
|
@@ -173,4 +141,4 @@ declare class SimpleMongoReader implements BaseReader<Document> {
|
|
|
173
141
|
loadData<TSchema extends Document$1 = Document$1>(dbName: string, collectionName: string, fieldNames?: string[], separator?: string, filterQuery?: Filter<TSchema>, maxDocs?: number, metadataNames?: string[]): Promise<Document[]>;
|
|
174
142
|
}
|
|
175
143
|
|
|
176
|
-
export { MongoDBAtlasVectorSearch,
|
|
144
|
+
export { MongoDBAtlasVectorSearch, MongoKVStore, SimpleMongoReader };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseKVStore, StoredValue,
|
|
1
|
+
import { BaseKVStore, StoredValue, BaseVectorStore, VectorStoreQuery, BaseEmbedding, VectorStoreBaseParams, BaseNode, VectorStoreQueryResult, BaseReader, Document } from '@vectorstores/core';
|
|
2
2
|
import { MongoClient, BulkWriteOptions, Collection, Document as Document$1, Filter } from 'mongodb';
|
|
3
3
|
|
|
4
4
|
interface MongoKVStoreConfig {
|
|
@@ -17,39 +17,6 @@ declare class MongoKVStore extends BaseKVStore {
|
|
|
17
17
|
delete(key: string, collectionName?: string): Promise<boolean>;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
interface MongoDBDocumentStoreConfig {
|
|
21
|
-
mongoKVStore: MongoKVStore;
|
|
22
|
-
namespace?: string;
|
|
23
|
-
}
|
|
24
|
-
declare class MongoDocumentStore extends KVDocumentStore {
|
|
25
|
-
constructor({ mongoKVStore, namespace }: MongoDBDocumentStoreConfig);
|
|
26
|
-
/**
|
|
27
|
-
* Static method for creating an instance using a MongoClient.
|
|
28
|
-
* @returns Instance of MongoDBDocumentStore
|
|
29
|
-
* @param mongoClient - MongoClient instance
|
|
30
|
-
* @param dbName - Database name
|
|
31
|
-
* @param collectionName - Collection name
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const mongoClient = new MongoClient("mongodb://localhost:27017");
|
|
35
|
-
* const documentStore = MongoDBDocumentStore.fromMongoClient(mongoClient, "my_db", "my_collection");
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
static fromMongoClient(mongoClient: MongoClient, dbName?: string, collectionName?: string): MongoDocumentStore;
|
|
39
|
-
/**
|
|
40
|
-
* Static method for creating an instance using a connection string.
|
|
41
|
-
* @returns Instance of MongoDBDocumentStore
|
|
42
|
-
* @param connectionString - MongoDB connection string
|
|
43
|
-
* @param dbName - Database name
|
|
44
|
-
* @param collectionName - Collection name
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* const documentStore = MongoDBDocumentStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
static fromConnectionString(connectionString: string, dbName?: string, collectionName?: string): MongoDocumentStore;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
20
|
/**
|
|
54
21
|
* Vector store that uses MongoDB Atlas for storage and vector search.
|
|
55
22
|
* This store uses the $vectorSearch aggregation stage to perform vector similarity search.
|
|
@@ -144,6 +111,7 @@ declare class MongoDBAtlasVectorSearch extends BaseVectorStore {
|
|
|
144
111
|
* @returns List of nodes and their similarities
|
|
145
112
|
*/
|
|
146
113
|
query(query: VectorStoreQuery, options?: object): Promise<VectorStoreQueryResult>;
|
|
114
|
+
exists(refDocId: string): Promise<boolean>;
|
|
147
115
|
}
|
|
148
116
|
|
|
149
117
|
/**
|
|
@@ -173,4 +141,4 @@ declare class SimpleMongoReader implements BaseReader<Document> {
|
|
|
173
141
|
loadData<TSchema extends Document$1 = Document$1>(dbName: string, collectionName: string, fieldNames?: string[], separator?: string, filterQuery?: Filter<TSchema>, maxDocs?: number, metadataNames?: string[]): Promise<Document[]>;
|
|
174
142
|
}
|
|
175
143
|
|
|
176
|
-
export { MongoDBAtlasVectorSearch,
|
|
144
|
+
export { MongoDBAtlasVectorSearch, MongoKVStore, SimpleMongoReader };
|
package/dist/index.edge-light.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { BaseKVStore,
|
|
2
|
-
import { MongoClient } from 'mongodb';
|
|
1
|
+
import { BaseKVStore, BaseVectorStore, nodeToMetadata, MetadataMode, metadataDictToNode, FilterCondition, Document } from '@vectorstores/core';
|
|
3
2
|
import { getEnv } from '@vectorstores/env';
|
|
4
|
-
|
|
5
|
-
var version = "0.1.2";
|
|
6
|
-
var pkg = {
|
|
7
|
-
version: version};
|
|
3
|
+
import { MongoClient } from 'mongodb';
|
|
8
4
|
|
|
9
5
|
const DEFAULT_DB_NAME = "KVStoreDB";
|
|
10
6
|
const DEFAULT_COLLECTION_NAME = "KVStoreCollection";
|
|
@@ -73,61 +69,9 @@ class MongoKVStore extends BaseKVStore {
|
|
|
73
69
|
}
|
|
74
70
|
}
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
constructor({ mongoKVStore, namespace }){
|
|
80
|
-
super(mongoKVStore, namespace);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Static method for creating an instance using a MongoClient.
|
|
84
|
-
* @returns Instance of MongoDBDocumentStore
|
|
85
|
-
* @param mongoClient - MongoClient instance
|
|
86
|
-
* @param dbName - Database name
|
|
87
|
-
* @param collectionName - Collection name
|
|
88
|
-
* @example
|
|
89
|
-
* ```ts
|
|
90
|
-
* const mongoClient = new MongoClient("mongodb://localhost:27017");
|
|
91
|
-
* const documentStore = MongoDBDocumentStore.fromMongoClient(mongoClient, "my_db", "my_collection");
|
|
92
|
-
* ```
|
|
93
|
-
*/ static fromMongoClient(mongoClient, dbName = DEFAULT_DATABASE, collectionName = DEFAULT_COLLECTION) {
|
|
94
|
-
const mongoKVStore = new MongoKVStore({
|
|
95
|
-
mongoClient,
|
|
96
|
-
dbName
|
|
97
|
-
});
|
|
98
|
-
mongoClient.appendMetadata({
|
|
99
|
-
name: "VECTORSTORES_MONGODB_DOC_STORE",
|
|
100
|
-
version: pkg.version
|
|
101
|
-
});
|
|
102
|
-
return new MongoDocumentStore({
|
|
103
|
-
mongoKVStore,
|
|
104
|
-
namespace: `${dbName}.${collectionName}`
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Static method for creating an instance using a connection string.
|
|
109
|
-
* @returns Instance of MongoDBDocumentStore
|
|
110
|
-
* @param connectionString - MongoDB connection string
|
|
111
|
-
* @param dbName - Database name
|
|
112
|
-
* @param collectionName - Collection name
|
|
113
|
-
* @example
|
|
114
|
-
* ```ts
|
|
115
|
-
* const documentStore = MongoDBDocumentStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
|
|
116
|
-
* ```
|
|
117
|
-
*/ static fromConnectionString(connectionString, dbName = DEFAULT_DATABASE, collectionName = DEFAULT_COLLECTION) {
|
|
118
|
-
const mongoClient = new MongoClient(connectionString, {
|
|
119
|
-
appName: "VECTORSTORES_JS"
|
|
120
|
-
});
|
|
121
|
-
const mongoKVStore = new MongoKVStore({
|
|
122
|
-
mongoClient,
|
|
123
|
-
dbName
|
|
124
|
-
});
|
|
125
|
-
return new MongoDocumentStore({
|
|
126
|
-
mongoKVStore,
|
|
127
|
-
namespace: `${dbName}.${collectionName}`
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
72
|
+
var version = "0.1.4";
|
|
73
|
+
var pkg = {
|
|
74
|
+
version: version};
|
|
131
75
|
|
|
132
76
|
// define your Atlas Search index. See detail https://www.mongodb.com/docs/atlas/atlas-search/field-types/knn-vector/
|
|
133
77
|
const DEFAULT_EMBEDDING_DEFINITION = {
|
|
@@ -333,6 +277,15 @@ function toMongoDBFilter(filters) {
|
|
|
333
277
|
};
|
|
334
278
|
return result;
|
|
335
279
|
}
|
|
280
|
+
async exists(refDocId) {
|
|
281
|
+
const collection = await this.ensureCollection();
|
|
282
|
+
const count = await collection.countDocuments({
|
|
283
|
+
[`${this.metadataKey}.ref_doc_id`]: refDocId
|
|
284
|
+
}, {
|
|
285
|
+
limit: 1
|
|
286
|
+
});
|
|
287
|
+
return count > 0;
|
|
288
|
+
}
|
|
336
289
|
}
|
|
337
290
|
|
|
338
291
|
/**
|
|
@@ -393,4 +346,4 @@ function toMongoDBFilter(filters) {
|
|
|
393
346
|
}
|
|
394
347
|
}
|
|
395
348
|
|
|
396
|
-
export { MongoDBAtlasVectorSearch,
|
|
349
|
+
export { MongoDBAtlasVectorSearch, MongoKVStore, SimpleMongoReader };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { BaseKVStore,
|
|
2
|
-
import { MongoClient } from 'mongodb';
|
|
1
|
+
import { BaseKVStore, BaseVectorStore, nodeToMetadata, MetadataMode, metadataDictToNode, FilterCondition, Document } from '@vectorstores/core';
|
|
3
2
|
import { getEnv } from '@vectorstores/env';
|
|
4
|
-
|
|
5
|
-
var version = "0.1.2";
|
|
6
|
-
var pkg = {
|
|
7
|
-
version: version};
|
|
3
|
+
import { MongoClient } from 'mongodb';
|
|
8
4
|
|
|
9
5
|
const DEFAULT_DB_NAME = "KVStoreDB";
|
|
10
6
|
const DEFAULT_COLLECTION_NAME = "KVStoreCollection";
|
|
@@ -73,61 +69,9 @@ class MongoKVStore extends BaseKVStore {
|
|
|
73
69
|
}
|
|
74
70
|
}
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
constructor({ mongoKVStore, namespace }){
|
|
80
|
-
super(mongoKVStore, namespace);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Static method for creating an instance using a MongoClient.
|
|
84
|
-
* @returns Instance of MongoDBDocumentStore
|
|
85
|
-
* @param mongoClient - MongoClient instance
|
|
86
|
-
* @param dbName - Database name
|
|
87
|
-
* @param collectionName - Collection name
|
|
88
|
-
* @example
|
|
89
|
-
* ```ts
|
|
90
|
-
* const mongoClient = new MongoClient("mongodb://localhost:27017");
|
|
91
|
-
* const documentStore = MongoDBDocumentStore.fromMongoClient(mongoClient, "my_db", "my_collection");
|
|
92
|
-
* ```
|
|
93
|
-
*/ static fromMongoClient(mongoClient, dbName = DEFAULT_DATABASE, collectionName = DEFAULT_COLLECTION) {
|
|
94
|
-
const mongoKVStore = new MongoKVStore({
|
|
95
|
-
mongoClient,
|
|
96
|
-
dbName
|
|
97
|
-
});
|
|
98
|
-
mongoClient.appendMetadata({
|
|
99
|
-
name: "VECTORSTORES_MONGODB_DOC_STORE",
|
|
100
|
-
version: pkg.version
|
|
101
|
-
});
|
|
102
|
-
return new MongoDocumentStore({
|
|
103
|
-
mongoKVStore,
|
|
104
|
-
namespace: `${dbName}.${collectionName}`
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Static method for creating an instance using a connection string.
|
|
109
|
-
* @returns Instance of MongoDBDocumentStore
|
|
110
|
-
* @param connectionString - MongoDB connection string
|
|
111
|
-
* @param dbName - Database name
|
|
112
|
-
* @param collectionName - Collection name
|
|
113
|
-
* @example
|
|
114
|
-
* ```ts
|
|
115
|
-
* const documentStore = MongoDBDocumentStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
|
|
116
|
-
* ```
|
|
117
|
-
*/ static fromConnectionString(connectionString, dbName = DEFAULT_DATABASE, collectionName = DEFAULT_COLLECTION) {
|
|
118
|
-
const mongoClient = new MongoClient(connectionString, {
|
|
119
|
-
appName: "VECTORSTORES_JS"
|
|
120
|
-
});
|
|
121
|
-
const mongoKVStore = new MongoKVStore({
|
|
122
|
-
mongoClient,
|
|
123
|
-
dbName
|
|
124
|
-
});
|
|
125
|
-
return new MongoDocumentStore({
|
|
126
|
-
mongoKVStore,
|
|
127
|
-
namespace: `${dbName}.${collectionName}`
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
72
|
+
var version = "0.1.4";
|
|
73
|
+
var pkg = {
|
|
74
|
+
version: version};
|
|
131
75
|
|
|
132
76
|
// define your Atlas Search index. See detail https://www.mongodb.com/docs/atlas/atlas-search/field-types/knn-vector/
|
|
133
77
|
const DEFAULT_EMBEDDING_DEFINITION = {
|
|
@@ -333,6 +277,15 @@ function toMongoDBFilter(filters) {
|
|
|
333
277
|
};
|
|
334
278
|
return result;
|
|
335
279
|
}
|
|
280
|
+
async exists(refDocId) {
|
|
281
|
+
const collection = await this.ensureCollection();
|
|
282
|
+
const count = await collection.countDocuments({
|
|
283
|
+
[`${this.metadataKey}.ref_doc_id`]: refDocId
|
|
284
|
+
}, {
|
|
285
|
+
limit: 1
|
|
286
|
+
});
|
|
287
|
+
return count > 0;
|
|
288
|
+
}
|
|
336
289
|
}
|
|
337
290
|
|
|
338
291
|
/**
|
|
@@ -393,4 +346,4 @@ function toMongoDBFilter(filters) {
|
|
|
393
346
|
}
|
|
394
347
|
}
|
|
395
348
|
|
|
396
|
-
export { MongoDBAtlasVectorSearch,
|
|
349
|
+
export { MongoDBAtlasVectorSearch, MongoKVStore, SimpleMongoReader };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectorstores/mongodb",
|
|
3
3
|
"description": "MongoDB Storage for vectorstores",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"vitest": "2.1.0",
|
|
38
38
|
"mongodb-memory-server": "^10.1.4",
|
|
39
|
-
"@vectorstores/core": "0.1.
|
|
39
|
+
"@vectorstores/core": "0.1.4",
|
|
40
40
|
"@vectorstores/env": "0.1.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@vectorstores/core": "0.1.
|
|
43
|
+
"@vectorstores/core": "0.1.4",
|
|
44
44
|
"@vectorstores/env": "0.1.0"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|