@remit/search-service 0.0.1 → 0.0.2
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/package.json +64 -64
- package/src/semantic-search.integ.test.ts +52 -54
package/package.json
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
2
|
+
"name": "@remit/search-service",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"types": "src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./src/index.ts",
|
|
10
|
+
"default": "./src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"./from-env": {
|
|
13
|
+
"types": "./src/from-env.ts",
|
|
14
|
+
"default": "./src/from-env.ts"
|
|
15
|
+
},
|
|
16
|
+
"./s3-vectors": {
|
|
17
|
+
"types": "./src/s3-vectors.ts",
|
|
18
|
+
"default": "./src/s3-vectors.ts"
|
|
19
|
+
},
|
|
20
|
+
"./bedrock": {
|
|
21
|
+
"types": "./src/bedrock.ts",
|
|
22
|
+
"default": "./src/bedrock.ts"
|
|
23
|
+
},
|
|
24
|
+
"./sqlite-vec": {
|
|
25
|
+
"types": "./src/sqlite-vec.ts",
|
|
26
|
+
"default": "./src/sqlite-vec.ts"
|
|
27
|
+
},
|
|
28
|
+
"./pgvector": {
|
|
29
|
+
"types": "./src/pgvector.ts",
|
|
30
|
+
"default": "./src/pgvector.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test:typecheck": "tsgo --noEmit",
|
|
35
|
+
"test:run": "node --env-file=../../localhost-test-unit.env --import tsx --test 'src/**/*.test.ts'",
|
|
36
|
+
"test:integ": "RUN_INTEG_TESTS=1 node --env-file=../../localhost-test-unit.env --import tsx --test 'src/**/*.integ.test.ts'",
|
|
37
|
+
"test": "npm run test:typecheck && npm run test:run"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@huggingface/transformers": "^4.2.0",
|
|
41
|
+
"@remit/domain-enums": "*",
|
|
42
|
+
"@remit/api-openapi-types": "*",
|
|
43
|
+
"better-sqlite3": "^12.11.1",
|
|
44
|
+
"p-limit": "^6.2.0",
|
|
45
|
+
"pg": "^8.0.0",
|
|
46
|
+
"sqlite-vec": "^0.1.9",
|
|
47
|
+
"zod": "*"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@aws-sdk/client-bedrock-runtime": "*",
|
|
51
|
+
"@aws-sdk/client-s3vectors": "*",
|
|
52
|
+
"@remit/storage-service": "*",
|
|
53
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
54
|
+
"@types/pg": "^8.20.0",
|
|
55
|
+
"aws-sdk-client-mock": "*"
|
|
56
|
+
},
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "git+https://github.com/remit-mail/remit.git",
|
|
64
|
+
"directory": "packages/search-service"
|
|
65
|
+
}
|
|
66
66
|
}
|
|
@@ -64,67 +64,65 @@ const DENTIST = message(
|
|
|
64
64
|
"This is a reminder that your dental check-up is scheduled for next Monday at nine in the morning. Call us to reschedule.",
|
|
65
65
|
);
|
|
66
66
|
|
|
67
|
-
describe(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let search: SearchService;
|
|
67
|
+
describe("semantic search over real local backends", {
|
|
68
|
+
skip: !process.env.RUN_INTEG_TESTS,
|
|
69
|
+
}, () => {
|
|
70
|
+
let dir: string;
|
|
71
|
+
let dbPath: string;
|
|
72
|
+
let search: SearchService;
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
await search.index(FLIGHT);
|
|
83
|
-
await search.index(FINANCE);
|
|
84
|
-
await search.index(DENTIST);
|
|
74
|
+
before(async () => {
|
|
75
|
+
dir = mkdtempSync(join(tmpdir(), "remit-vec-"));
|
|
76
|
+
dbPath = join(dir, "vectors.sqlite");
|
|
77
|
+
search = createSearchService({
|
|
78
|
+
store: createSqliteVectorStore({ path: dbPath }),
|
|
79
|
+
embedder: createLocalEmbeddingService(),
|
|
85
80
|
});
|
|
81
|
+
await search.index(FLIGHT);
|
|
82
|
+
await search.index(FINANCE);
|
|
83
|
+
await search.index(DENTIST);
|
|
84
|
+
});
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
after(() => {
|
|
87
|
+
rmSync(dir, { recursive: true, force: true });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("a paraphrased query returns the semantically closest message", async () => {
|
|
91
|
+
const results = await search.search({
|
|
92
|
+
query: "air travel reservation booking",
|
|
93
|
+
accountConfigId: ACCOUNT_CONFIG_ID,
|
|
94
|
+
limit: 3,
|
|
89
95
|
});
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
assert.ok(results.length > 0, "expected at least one hit");
|
|
98
|
+
assert.equal(
|
|
99
|
+
results[0].messageId,
|
|
100
|
+
"msg-flight",
|
|
101
|
+
`expected the flight message to rank first, got ${results
|
|
102
|
+
.map((r) => r.messageId)
|
|
103
|
+
.join(", ")}`,
|
|
104
|
+
);
|
|
105
|
+
});
|
|
97
106
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
`expected the flight message to rank first, got ${results
|
|
103
|
-
.map((r) => r.messageId)
|
|
104
|
-
.join(", ")}`,
|
|
105
|
-
);
|
|
107
|
+
test("vectors persist to disk across store instances", async () => {
|
|
108
|
+
const reopened = createSearchService({
|
|
109
|
+
store: createSqliteVectorStore({ path: dbPath }),
|
|
110
|
+
embedder: createLocalEmbeddingService(),
|
|
106
111
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
embedder: createLocalEmbeddingService(),
|
|
112
|
-
});
|
|
113
|
-
const results = await reopened.search({
|
|
114
|
-
query: "earnings and revenue report",
|
|
115
|
-
accountConfigId: ACCOUNT_CONFIG_ID,
|
|
116
|
-
limit: 3,
|
|
117
|
-
});
|
|
118
|
-
assert.equal(results[0].messageId, "msg-finance");
|
|
112
|
+
const results = await reopened.search({
|
|
113
|
+
query: "earnings and revenue report",
|
|
114
|
+
accountConfigId: ACCOUNT_CONFIG_ID,
|
|
115
|
+
limit: 3,
|
|
119
116
|
});
|
|
117
|
+
assert.equal(results[0].messageId, "msg-finance");
|
|
118
|
+
});
|
|
120
119
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
assert.equal(results.length, 0);
|
|
120
|
+
test("the metadata filter scopes results to the account", async () => {
|
|
121
|
+
const results = await search.search({
|
|
122
|
+
query: "air travel reservation booking",
|
|
123
|
+
accountConfigId: "other-account",
|
|
124
|
+
limit: 3,
|
|
128
125
|
});
|
|
129
|
-
|
|
130
|
-
);
|
|
126
|
+
assert.equal(results.length, 0);
|
|
127
|
+
});
|
|
128
|
+
});
|