@storecraft/database-mongodb 1.0.14 → 1.0.15

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
@@ -8,7 +8,7 @@
8
8
  [![MongoDB](https://github.com/store-craft/storecraft/actions/workflows/test.database-mongodb.yml/badge.svg)](https://github.com/store-craft/storecraft/actions/workflows/test.database-mongodb.yml)
9
9
 
10
10
  Official `mongodb` driver for `StoreCraft` on **Node.js** / **Deno** / **Bun** platforms.
11
- Also, an example of [Semantic Vector Search](https://www.mongodb.com/developer/products/atlas/semantic-search-mongodb-atlas-vector-search/) extension at `@storecraft/database-mongodb/vector-search-extension`
11
+ Also, official support for mongo-db as vector store.
12
12
 
13
13
  ```bash
14
14
  npm i @storecraft/database-mongodb
@@ -24,23 +24,19 @@ import { NodePlatform } from '@storecraft/core/platform/node';
24
24
  import { MongoDB } from '@storecraft/database-mongodb'
25
25
  import { migrateToLatest } from '@storecraft/database-mongodb/migrate.js'
26
26
  import { NodeLocalStorage } from '@storecraft/core/storage/node'
27
- import { MongoVectorSearch } from '@storecraft/database-mongodb/vector-search-extension'
27
+ import { MongoVectorStore } from '@storecraft/database-mongodb/vector-store'
28
28
 
29
- const app = new App(
30
- {
31
- auth_admins_emails: ['admin@sc.com'],
32
- auth_secret_access_token: 'auth_secret_access_token',
33
- auth_secret_refresh_token: 'auth_secret_refresh_token'
34
- }
35
- )
29
+ const app = new App()
36
30
  .withPlatform(new NodePlatform())
37
- .withDatabase(new MongoDB({ db_name: 'test', url: '...', options: {}}))
38
- .withExtensions(
39
- 'mongo-vector-search': new MongoVectorSearch({ openai_key: process.env.OPENAI })
31
+ .withDatabase(new MongoDB({}))
32
+ .withVectorStore(
33
+ new MongoVectorStore({ embedder: new OpenAIEmbedder() })
40
34
  )
41
35
 
42
36
  await app.init();
43
37
  await migrateToLatest(app.db, false);
38
+ // cerate if not exists
39
+ await app.vectorstore.createVectorIndex(false, false);
44
40
 
45
41
  const server = http.createServer(app.handler).listen(
46
42
  8000,
@@ -51,62 +47,6 @@ const server = http.createServer(app.handler).listen(
51
47
 
52
48
  ```
53
49
 
54
- ## (Recommended) setup semantic/ai vector search extension for products
55
-
56
- 1. in [Atlas](https://cloud.mongodb.com/) dashboard, create a vector index (call it `vector_index`) for `products` collection:
57
-
58
- ```json
59
- {
60
- "fields": [
61
- {
62
- "numDimensions": 1536,
63
- "path": "embedding",
64
- "similarity": "cosine",
65
- "type": "vector"
66
- }
67
- ]
68
- }
69
- ```
70
-
71
- 2. Now, every upserted product will be eligible for semantic search by it's title + description.
72
- 3. The extension is publicly available via HTTP (`POST` request)
73
- ```js
74
- await fetch(
75
- 'http://localhost:8000/api/extensions/mongo-vector-search/search',
76
- {
77
- method: 'POST',
78
- body: JSON.stringify(
79
- {
80
- query: 'I am interested in Nintendo related clothing, such as shirts',
81
- limit: 1
82
- }
83
- )
84
- }
85
- )
86
- ```
87
-
88
- returns `ProductType[]` array
89
-
90
- ```json
91
- [
92
- {
93
- "title": "Super Mario T Shirt",
94
- "handle": "super-mario-t-shirt",
95
- "description": "This Super mario shirt is XL size and
96
- features a colorful print of Lugi and Mario.",
97
- "media": [
98
- "storage://images/super-mario-shirt_1738686680944_w_819_h_460.jpeg"
99
- ],
100
- "price": 100,
101
- "qty": 1,
102
- "active": true,
103
- "id": "pr_67a240e4000000d34bcf0743",
104
- "created_at": "2025-02-04T16:31:32.909Z",
105
- "updated_at": "2025-02-04T16:58:25.286Z"
106
- }
107
- ]
108
- ```
109
-
110
50
 
111
51
  ```text
112
52
  Author: Tomer Shalev <tomer.shalev@gmail.com>
@@ -1,7 +1,10 @@
1
1
  /**
2
+ * an older demo for extending storecraft with vector search.
3
+ * DO NOT USE this. Use the our official `MongoVectorSearch` insteas
4
+ *
2
5
  * @import {extension} from '@storecraft/core/extensions'
3
6
  */
4
- import { MongoDB } from './index.js';
7
+ import { MongoDB } from '../index.js';
5
8
  /**
6
9
  *
7
10
  * @typedef {object} Config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storecraft/database-mongodb",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
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)",