@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 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-small"
10
- export const EMBEDDINGS_VECTOR_LENGTH = 1536
10
+ export const EMBEDDINGS_MODEL_NAME = "text-embedding-3-large"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.375.0",
3
+ "version": "0.376.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "scripts": {
@@ -1,13 +1,22 @@
1
1
  /* @flow */
2
2
 
3
- const dispatch_indexer_queue = (queue, model_name, coll_name, op, doc, update_description) => {
4
-
5
- queue.add("index_item", {op, doc, model_name, coll_name, update_description}, {
6
- jobId: `index-item-${op}-${doc._id}`,
7
- removeOnComplete: true,
8
- removeOnFail: true,
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
@@ -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
- mappings_properties,
9
+ mappings,
10
10
  }: {
11
- index_id: string,
12
- mappings_properties: any
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
- if (exists) return
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("Error checking for index existance", JSON.stringify(err, null, 2))
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
+ // }
@@ -1,4 +1,4 @@
1
- const {Client} = require("@elastic/elasticsearch")
1
+ import {Client} from "@elastic/elasticsearch"
2
2
 
3
3
  // const is_docker = require("@rpcbase/std/is_docker")
4
4
  const is_docker = () => true
package/search/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./get_client"
2
2
  export * from "./ensure_index"
3
+ export * from "./constants"
@@ -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
+ )
@@ -4,3 +4,4 @@ require("./Policy")
4
4
  require("./ResetPasswordToken")
5
5
  require("./User")
6
6
  require("./UserStoredValues")
7
+ require("./SearchHistory")