@storecraft/database-mongodb 1.0.16 → 1.0.17
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/README.md +46 -4
- package/package.json +1 -1
- package/vector-store/index.js +2 -0
- package/vector-store/types.d.ts +3 -1
package/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Storecraft MongoDB driver for
|
1
|
+
# Storecraft MongoDB driver for node / deno / bun
|
2
2
|
|
3
3
|
<div style="text-align:center">
|
4
4
|
<img src='https://storecraft.app/storecraft-color.svg'
|
@@ -28,14 +28,27 @@ import { MongoVectorStore } from '@storecraft/database-mongodb/vector-store'
|
|
28
28
|
|
29
29
|
const app = new App()
|
30
30
|
.withPlatform(new NodePlatform())
|
31
|
-
.withDatabase(
|
31
|
+
.withDatabase(
|
32
|
+
new MongoDB(
|
33
|
+
{
|
34
|
+
url: process.env.MONGODB_URL,
|
35
|
+
db_name: process.env.MONGODB_NAME,
|
36
|
+
}
|
37
|
+
)
|
38
|
+
)
|
32
39
|
.withVectorStore(
|
33
|
-
new MongoVectorStore(
|
40
|
+
new MongoVectorStore(
|
41
|
+
{
|
42
|
+
embedder: new OpenAIEmbedder(),
|
43
|
+
url: process.env.MONGODB_VECTOR_STORE_URL ?? process.env.MONGODB_URL,
|
44
|
+
db_name: process.env.MONGODB_VECTOR_STORE_DB_NAME ?? process.env.MONGODB_NAME,
|
45
|
+
}
|
46
|
+
)
|
34
47
|
)
|
35
48
|
|
36
49
|
await app.init();
|
37
50
|
await migrateToLatest(app.db, false);
|
38
|
-
//
|
51
|
+
// create if not exists
|
39
52
|
await app.vectorstore.createVectorIndex(false, false);
|
40
53
|
|
41
54
|
const server = http.createServer(app.handler).listen(
|
@@ -47,6 +60,35 @@ const server = http.createServer(app.handler).listen(
|
|
47
60
|
|
48
61
|
```
|
49
62
|
|
63
|
+
|
64
|
+
Storecraft will search the following `env` variables
|
65
|
+
|
66
|
+
```bash
|
67
|
+
MONGODB_NAME=main
|
68
|
+
MONGODB_URL='mongodb-connection-string'
|
69
|
+
|
70
|
+
// also, this will default into `MONGODB_NAME`
|
71
|
+
MONGODB_VECTOR_STORE_DB_NAME=vector-store
|
72
|
+
// also, this will default into `MONGODB_URL`
|
73
|
+
MONGODB_VECTOR_STORE_URL='mongodb-connection-string'
|
74
|
+
```
|
75
|
+
|
76
|
+
So, you can instantiate with empty config
|
77
|
+
|
78
|
+
```ts
|
79
|
+
.withDatabase(
|
80
|
+
new MongoDB()
|
81
|
+
)
|
82
|
+
.withVectorStore(
|
83
|
+
new MongoVectorStore(
|
84
|
+
{
|
85
|
+
embedder: new OpenAIEmbedder(),
|
86
|
+
}
|
87
|
+
)
|
88
|
+
)
|
89
|
+
```
|
90
|
+
|
91
|
+
|
50
92
|
## Testing Locally (I recommend to use `Atlas`)
|
51
93
|
|
52
94
|
1. First start a `mongo-db` server
|
package/package.json
CHANGED
package/vector-store/index.js
CHANGED
@@ -68,6 +68,7 @@ export class MongoVectorStore {
|
|
68
68
|
};
|
69
69
|
}
|
70
70
|
|
71
|
+
/** @type {VectorStore["metric"]} */
|
71
72
|
get metric() {
|
72
73
|
switch(this.config.similarity) {
|
73
74
|
case 'cosine': return 'cosine';
|
@@ -76,6 +77,7 @@ export class MongoVectorStore {
|
|
76
77
|
}
|
77
78
|
};
|
78
79
|
|
80
|
+
/** @type {VectorStore["dimensions"]} */
|
79
81
|
get dimensions() {
|
80
82
|
return this.config.dimensions;
|
81
83
|
};
|
package/vector-store/types.d.ts
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
|
2
2
|
import type { AIEmbedder } from '@storecraft/core/ai';
|
3
3
|
import type { MongoClientOptions } from 'mongodb';
|
4
|
-
export
|
4
|
+
export {
|
5
|
+
MongoVectorStore, DEFAULT_INDEX_NAME, EMBEDDING_KEY_PATH, NAMESPACE_KEY
|
6
|
+
} from './index.js';
|
5
7
|
|
6
8
|
export type Config = {
|
7
9
|
/**
|