@rpcbase/server 0.375.0 → 0.376.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/openai.js +2 -2
- package/package.json +1 -1
- package/queue/dispatch_indexer_queue.js +17 -8
- package/rts/index.js +8 -1
- package/search/constants.ts +1 -0
- package/search/ensure_index.ts +24 -8
- package/search/get_client.ts +1 -1
- package/search/index.ts +1 -0
- package/src/models/SearchHistory.ts +22 -0
- package/src/models/index.js +1 -0
package/openai.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const OpenAI = require("openai")
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
const {OPENAI_API_KEY} = process.env
|
|
4
5
|
|
|
5
6
|
export const openai = new OpenAI({
|
|
6
7
|
apiKey: OPENAI_API_KEY,
|
|
7
8
|
})
|
|
8
9
|
|
|
9
|
-
export const EMBEDDINGS_MODEL_NAME = "text-embedding-3-
|
|
10
|
-
export const EMBEDDINGS_VECTOR_LENGTH = 1536
|
|
10
|
+
export const EMBEDDINGS_MODEL_NAME = "text-embedding-3-large"
|
package/package.json
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
|
|
3
|
-
const dispatch_indexer_queue = (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
const dispatch_indexer_queue = (
|
|
4
|
+
queue,
|
|
5
|
+
model_name,
|
|
6
|
+
coll_name,
|
|
7
|
+
op,
|
|
8
|
+
doc,
|
|
9
|
+
update_description,
|
|
10
|
+
) => {
|
|
11
|
+
queue.add(
|
|
12
|
+
"index_item",
|
|
13
|
+
{op, doc, model_name, coll_name, update_description},
|
|
14
|
+
{
|
|
15
|
+
jobId: `index-item-${op}-${doc._id}-${Date.now()}`,
|
|
16
|
+
removeOnComplete: true,
|
|
17
|
+
removeOnFail: true,
|
|
18
|
+
},
|
|
19
|
+
)
|
|
10
20
|
}
|
|
11
21
|
|
|
12
|
-
|
|
13
22
|
module.exports = dispatch_indexer_queue
|
package/rts/index.js
CHANGED
|
@@ -211,7 +211,7 @@ const add_change_stream = (socket_id, {model_name, query, query_key, options}) =
|
|
|
211
211
|
try {
|
|
212
212
|
model = mongoose.model(model_name)
|
|
213
213
|
} catch (err) {
|
|
214
|
-
console.error("ERROR registering model:", model_name)
|
|
214
|
+
console.error("add change stream:ERROR registering model:", model_name)
|
|
215
215
|
console.error(err)
|
|
216
216
|
return
|
|
217
217
|
}
|
|
@@ -261,6 +261,13 @@ const add_change_stream = (socket_id, {model_name, query, query_key, options}) =
|
|
|
261
261
|
|
|
262
262
|
|
|
263
263
|
const run_query = async(socket_id, {model_name, query, query_key, options}) => {
|
|
264
|
+
// Check if the model is registered
|
|
265
|
+
if (!mongoose.models[model_name]) {
|
|
266
|
+
// throw new Error(`Model "${model_name}" is not registered.`)
|
|
267
|
+
console.error(colors.red("ERROR: model not registered"), model_name, "will skip query")
|
|
268
|
+
return
|
|
269
|
+
}
|
|
270
|
+
|
|
264
271
|
const model = mongoose.model(model_name)
|
|
265
272
|
|
|
266
273
|
log("run_query", {model_name, query, query_key, options})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_SEARCH_EMBEDDINGS_DIMENSIONS = 2048
|
package/search/ensure_index.ts
CHANGED
|
@@ -6,26 +6,35 @@ const log = debug("rb:search:ensure_index")
|
|
|
6
6
|
|
|
7
7
|
export const ensure_index = async({
|
|
8
8
|
index_id,
|
|
9
|
-
|
|
9
|
+
mappings,
|
|
10
10
|
}: {
|
|
11
|
-
index_id: string
|
|
12
|
-
|
|
11
|
+
index_id: string;
|
|
12
|
+
mappings: any;
|
|
13
13
|
}) => {
|
|
14
14
|
const client = get_client()
|
|
15
15
|
|
|
16
16
|
try {
|
|
17
17
|
const exists = await client.indices.exists({index: index_id})
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
if (exists) {
|
|
20
|
+
await client.indices.putMapping({
|
|
21
|
+
index: index_id,
|
|
22
|
+
body: mappings,
|
|
23
|
+
})
|
|
24
|
+
log("updated index mappings", index_id)
|
|
25
|
+
return
|
|
26
|
+
}
|
|
19
27
|
} catch (err) {
|
|
20
|
-
console.log(
|
|
28
|
+
console.log(
|
|
29
|
+
"Error checking for index existance",
|
|
30
|
+
JSON.stringify(err, null, 2),
|
|
31
|
+
)
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
const res = await client.indices.create({
|
|
24
35
|
index: index_id,
|
|
25
36
|
body: {
|
|
26
|
-
mappings
|
|
27
|
-
properties: mappings_properties,
|
|
28
|
-
},
|
|
37
|
+
mappings,
|
|
29
38
|
},
|
|
30
39
|
})
|
|
31
40
|
|
|
@@ -34,4 +43,11 @@ export const ensure_index = async({
|
|
|
34
43
|
|
|
35
44
|
log("created index", index_id)
|
|
36
45
|
}
|
|
46
|
+
|
|
37
47
|
console.log("ensure_index.ts")
|
|
48
|
+
|
|
49
|
+
// {
|
|
50
|
+
// dynamic: true,
|
|
51
|
+
// // date_detection: false,
|
|
52
|
+
// properties: mappings_properties,
|
|
53
|
+
// }
|
package/search/get_client.ts
CHANGED
package/search/index.ts
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import mongoose, {Schema, Model, Document} from "@rpcbase/server/mongoose"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
interface ISearchHistory extends Document {
|
|
5
|
+
server_timestamp_ms: number;
|
|
6
|
+
context: any;
|
|
7
|
+
data: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const SearchHistorySchema: Schema<ISearchHistory> = new Schema(
|
|
11
|
+
{
|
|
12
|
+
server_timestamp_ms: Number,
|
|
13
|
+
context: mongoose.Schema.Types.Mixed,
|
|
14
|
+
data: mongoose.Schema.Types.Mixed,
|
|
15
|
+
},
|
|
16
|
+
{timestamps: true},
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
export const SearchHistory: Model<ISearchHistory> = mongoose.model<ISearchHistory>(
|
|
20
|
+
"SearchHistory",
|
|
21
|
+
SearchHistorySchema,
|
|
22
|
+
)
|
package/src/models/index.js
CHANGED