@storecraft/database-mongodb 1.0.16 → 1.0.18

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 CHANGED
@@ -1,4 +1,4 @@
1
- # Storecraft MongoDB driver for Node.js
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(new MongoDB({}))
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({ embedder: new OpenAIEmbedder() })
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
- // cerate if not exists
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
@@ -1,6 +1,6 @@
1
1
  import { Db, MongoClient } from 'mongodb';
2
2
  import { MongoDB } from '../index.js'
3
- import { templates } from '@storecraft/core/assets/seed-templates.js'
3
+ import { templates } from '@storecraft/core/assets/seed-templates-v1.js'
4
4
 
5
5
  /**
6
6
  *
@@ -0,0 +1,46 @@
1
+ import { Db, MongoClient } from 'mongodb';
2
+ import { MongoDB } from '../index.js'
3
+ import {
4
+ templates as templates_corrections
5
+ } from '@storecraft/core/assets/seed-templates-v3-update-previous-templates-with-subject.js';
6
+
7
+ /**
8
+ *
9
+ * @param {Db} db
10
+ * @param {MongoClient} client
11
+ */
12
+ export async function up(db, client) {
13
+
14
+ const session = client.startSession();
15
+ try {
16
+ await session.withTransaction(
17
+ async (s) => {
18
+ /** @type {MongoDB} */
19
+ // @ts-ignore
20
+ const driver = client.__db_driver;
21
+
22
+ for (const template of templates_corrections) {
23
+ await driver.resources.templates._col.updateOne(
24
+ { id: template.id },
25
+ {
26
+ $set: {
27
+ template_subject: template.template_subject,
28
+ },
29
+ },
30
+ { session, upsert: false }
31
+ );
32
+ }
33
+ }
34
+ );
35
+ } finally {
36
+ await session.endSession();
37
+ }
38
+ }
39
+
40
+ /**
41
+ *
42
+ * @param {Db} db
43
+ * @param {MongoClient} client
44
+ */
45
+ export async function down(db, client) {
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storecraft/database-mongodb",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Storecraft database driver for mongodb on node / bun / deno platform",
5
5
  "license": "MIT",
6
6
  "author": "Tomer Shalev (https://github.com/store-craft)",
@@ -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
  };
@@ -1,7 +1,9 @@
1
1
 
2
2
  import type { AIEmbedder } from '@storecraft/core/ai';
3
3
  import type { MongoClientOptions } from 'mongodb';
4
- export * from './index.js';
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
  /**