cloison-runtime 0.1.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/LICENSE +21 -0
- package/README.md +313 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +47 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/index.d.ts +57 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +27 -0
- package/dist/config/index.js.map +1 -0
- package/dist/credentials/index.d.ts +4 -0
- package/dist/credentials/index.d.ts.map +1 -0
- package/dist/credentials/index.js +3 -0
- package/dist/credentials/index.js.map +1 -0
- package/dist/credentials/proxy.d.ts +3 -0
- package/dist/credentials/proxy.d.ts.map +1 -0
- package/dist/credentials/proxy.js +11 -0
- package/dist/credentials/proxy.js.map +1 -0
- package/dist/credentials/store.d.ts +7 -0
- package/dist/credentials/store.d.ts.map +1 -0
- package/dist/credentials/store.js +115 -0
- package/dist/credentials/store.js.map +1 -0
- package/dist/credentials/types.d.ts +14 -0
- package/dist/credentials/types.d.ts.map +1 -0
- package/dist/credentials/types.js +2 -0
- package/dist/credentials/types.js.map +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/runner.d.ts +7 -0
- package/dist/hooks/runner.d.ts.map +1 -0
- package/dist/hooks/runner.js +20 -0
- package/dist/hooks/runner.js.map +1 -0
- package/dist/hooks/types.d.ts +39 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +2 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/infra/env.d.ts +2 -0
- package/dist/infra/env.d.ts.map +1 -0
- package/dist/infra/env.js +6 -0
- package/dist/infra/env.js.map +1 -0
- package/dist/infra/warning-filter.d.ts +8 -0
- package/dist/infra/warning-filter.d.ts.map +1 -0
- package/dist/infra/warning-filter.js +66 -0
- package/dist/infra/warning-filter.js.map +1 -0
- package/dist/logging/subsystem.d.ts +29 -0
- package/dist/logging/subsystem.d.ts.map +1 -0
- package/dist/logging/subsystem.js +322 -0
- package/dist/logging/subsystem.js.map +1 -0
- package/dist/memory/embedding-batch.d.ts +38 -0
- package/dist/memory/embedding-batch.d.ts.map +1 -0
- package/dist/memory/embedding-batch.js +253 -0
- package/dist/memory/embedding-batch.js.map +1 -0
- package/dist/memory/embedding-cache.d.ts +16 -0
- package/dist/memory/embedding-cache.d.ts.map +1 -0
- package/dist/memory/embedding-cache.js +113 -0
- package/dist/memory/embedding-cache.js.map +1 -0
- package/dist/memory/embeddings-debug.d.ts +2 -0
- package/dist/memory/embeddings-debug.d.ts.map +1 -0
- package/dist/memory/embeddings-debug.js +12 -0
- package/dist/memory/embeddings-debug.js.map +1 -0
- package/dist/memory/embeddings.d.ts +17 -0
- package/dist/memory/embeddings.d.ts.map +1 -0
- package/dist/memory/embeddings.js +203 -0
- package/dist/memory/embeddings.js.map +1 -0
- package/dist/memory/file-indexer.d.ts +26 -0
- package/dist/memory/file-indexer.d.ts.map +1 -0
- package/dist/memory/file-indexer.js +260 -0
- package/dist/memory/file-indexer.js.map +1 -0
- package/dist/memory/fs-utils.d.ts +12 -0
- package/dist/memory/fs-utils.d.ts.map +1 -0
- package/dist/memory/fs-utils.js +24 -0
- package/dist/memory/fs-utils.js.map +1 -0
- package/dist/memory/hybrid.d.ts +46 -0
- package/dist/memory/hybrid.d.ts.map +1 -0
- package/dist/memory/hybrid.js +85 -0
- package/dist/memory/hybrid.js.map +1 -0
- package/dist/memory/index.d.ts +17 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +15 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/internal.d.ts +39 -0
- package/dist/memory/internal.d.ts.map +1 -0
- package/dist/memory/internal.js +292 -0
- package/dist/memory/internal.js.map +1 -0
- package/dist/memory/manager-search.d.ts +61 -0
- package/dist/memory/manager-search.d.ts.map +1 -0
- package/dist/memory/manager-search.js +102 -0
- package/dist/memory/manager-search.js.map +1 -0
- package/dist/memory/mmr.d.ts +63 -0
- package/dist/memory/mmr.d.ts.map +1 -0
- package/dist/memory/mmr.js +165 -0
- package/dist/memory/mmr.js.map +1 -0
- package/dist/memory/query-expansion.d.ts +42 -0
- package/dist/memory/query-expansion.d.ts.map +1 -0
- package/dist/memory/query-expansion.js +776 -0
- package/dist/memory/query-expansion.js.map +1 -0
- package/dist/memory/session-indexer.d.ts +41 -0
- package/dist/memory/session-indexer.d.ts.map +1 -0
- package/dist/memory/session-indexer.js +367 -0
- package/dist/memory/session-indexer.js.map +1 -0
- package/dist/memory/simple-manager.d.ts +29 -0
- package/dist/memory/simple-manager.d.ts.map +1 -0
- package/dist/memory/simple-manager.js +216 -0
- package/dist/memory/simple-manager.js.map +1 -0
- package/dist/memory/sqlite.d.ts +2 -0
- package/dist/memory/sqlite.d.ts.map +1 -0
- package/dist/memory/sqlite.js +16 -0
- package/dist/memory/sqlite.js.map +1 -0
- package/dist/memory/ssrf.d.ts +18 -0
- package/dist/memory/ssrf.d.ts.map +1 -0
- package/dist/memory/ssrf.js +396 -0
- package/dist/memory/ssrf.js.map +1 -0
- package/dist/memory/temporal-decay.d.ts +26 -0
- package/dist/memory/temporal-decay.d.ts.map +1 -0
- package/dist/memory/temporal-decay.js +120 -0
- package/dist/memory/temporal-decay.js.map +1 -0
- package/dist/memory/types.d.ts +95 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +2 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/package.json +68 -0
- package/dist/platform/index.d.ts +3 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +2 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/platform/platform.d.ts +3 -0
- package/dist/platform/platform.d.ts.map +1 -0
- package/dist/platform/platform.js +91 -0
- package/dist/platform/platform.js.map +1 -0
- package/dist/platform/types.d.ts +18 -0
- package/dist/platform/types.d.ts.map +1 -0
- package/dist/platform/types.js +2 -0
- package/dist/platform/types.js.map +1 -0
- package/dist/runtime/agent.d.ts +36 -0
- package/dist/runtime/agent.d.ts.map +1 -0
- package/dist/runtime/agent.js +250 -0
- package/dist/runtime/agent.js.map +1 -0
- package/dist/runtime/api-key-rotation.d.ts +26 -0
- package/dist/runtime/api-key-rotation.d.ts.map +1 -0
- package/dist/runtime/api-key-rotation.js +174 -0
- package/dist/runtime/api-key-rotation.js.map +1 -0
- package/dist/runtime/context-guard.d.ts +32 -0
- package/dist/runtime/context-guard.d.ts.map +1 -0
- package/dist/runtime/context-guard.js +61 -0
- package/dist/runtime/context-guard.js.map +1 -0
- package/dist/runtime/failover-error.d.ts +62 -0
- package/dist/runtime/failover-error.d.ts.map +1 -0
- package/dist/runtime/failover-error.js +733 -0
- package/dist/runtime/failover-error.js.map +1 -0
- package/dist/runtime/failover-policy.d.ts +5 -0
- package/dist/runtime/failover-policy.d.ts.map +1 -0
- package/dist/runtime/failover-policy.js +18 -0
- package/dist/runtime/failover-policy.js.map +1 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +13 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/memory-flush.d.ts +24 -0
- package/dist/runtime/memory-flush.d.ts.map +1 -0
- package/dist/runtime/memory-flush.js +64 -0
- package/dist/runtime/memory-flush.js.map +1 -0
- package/dist/runtime/memory-tools.d.ts +14 -0
- package/dist/runtime/memory-tools.d.ts.map +1 -0
- package/dist/runtime/memory-tools.js +58 -0
- package/dist/runtime/memory-tools.js.map +1 -0
- package/dist/runtime/model-fallback.d.ts +56 -0
- package/dist/runtime/model-fallback.d.ts.map +1 -0
- package/dist/runtime/model-fallback.js +301 -0
- package/dist/runtime/model-fallback.js.map +1 -0
- package/dist/runtime/model-fallback.types.d.ts +14 -0
- package/dist/runtime/model-fallback.types.d.ts.map +1 -0
- package/dist/runtime/model-fallback.types.js +3 -0
- package/dist/runtime/model-fallback.types.js.map +1 -0
- package/dist/runtime/retry.d.ts +24 -0
- package/dist/runtime/retry.d.ts.map +1 -0
- package/dist/runtime/retry.js +100 -0
- package/dist/runtime/retry.js.map +1 -0
- package/dist/runtime/session-pruning.d.ts +22 -0
- package/dist/runtime/session-pruning.d.ts.map +1 -0
- package/dist/runtime/session-pruning.js +118 -0
- package/dist/runtime/session-pruning.js.map +1 -0
- package/dist/runtime/stream-adapters.d.ts +11 -0
- package/dist/runtime/stream-adapters.d.ts.map +1 -0
- package/dist/runtime/stream-adapters.js +46 -0
- package/dist/runtime/stream-adapters.js.map +1 -0
- package/dist/runtime/subagent.d.ts +83 -0
- package/dist/runtime/subagent.d.ts.map +1 -0
- package/dist/runtime/subagent.js +190 -0
- package/dist/runtime/subagent.js.map +1 -0
- package/dist/runtime/tool-result-truncation.d.ts +25 -0
- package/dist/runtime/tool-result-truncation.d.ts.map +1 -0
- package/dist/runtime/tool-result-truncation.js +115 -0
- package/dist/runtime/tool-result-truncation.js.map +1 -0
- package/dist/sandbox/cgroup.d.ts +20 -0
- package/dist/sandbox/cgroup.d.ts.map +1 -0
- package/dist/sandbox/cgroup.js +82 -0
- package/dist/sandbox/cgroup.js.map +1 -0
- package/dist/sandbox/index.d.ts +12 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +10 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/ipc.d.ts +26 -0
- package/dist/sandbox/ipc.d.ts.map +1 -0
- package/dist/sandbox/ipc.js +154 -0
- package/dist/sandbox/ipc.js.map +1 -0
- package/dist/sandbox/manager.d.ts +4 -0
- package/dist/sandbox/manager.d.ts.map +1 -0
- package/dist/sandbox/manager.js +251 -0
- package/dist/sandbox/manager.js.map +1 -0
- package/dist/sandbox/namespace.d.ts +12 -0
- package/dist/sandbox/namespace.d.ts.map +1 -0
- package/dist/sandbox/namespace.js +119 -0
- package/dist/sandbox/namespace.js.map +1 -0
- package/dist/sandbox/proxy-tools.d.ts +14 -0
- package/dist/sandbox/proxy-tools.d.ts.map +1 -0
- package/dist/sandbox/proxy-tools.js +63 -0
- package/dist/sandbox/proxy-tools.js.map +1 -0
- package/dist/sandbox/rootfs.d.ts +20 -0
- package/dist/sandbox/rootfs.d.ts.map +1 -0
- package/dist/sandbox/rootfs.js +247 -0
- package/dist/sandbox/rootfs.js.map +1 -0
- package/dist/sandbox/seccomp-apply.d.ts +9 -0
- package/dist/sandbox/seccomp-apply.d.ts.map +1 -0
- package/dist/sandbox/seccomp-apply.js +227 -0
- package/dist/sandbox/seccomp-apply.js.map +1 -0
- package/dist/sandbox/seccomp.d.ts +13 -0
- package/dist/sandbox/seccomp.d.ts.map +1 -0
- package/dist/sandbox/seccomp.js +120 -0
- package/dist/sandbox/seccomp.js.map +1 -0
- package/dist/sandbox/types.d.ts +66 -0
- package/dist/sandbox/types.d.ts.map +1 -0
- package/dist/sandbox/types.js +8 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/sandbox/worker.d.ts +15 -0
- package/dist/sandbox/worker.d.ts.map +1 -0
- package/dist/sandbox/worker.js +151 -0
- package/dist/sandbox/worker.js.map +1 -0
- package/dist/sessions/index.d.ts +3 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/sessions/index.js +3 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/store.d.ts +17 -0
- package/dist/sessions/store.d.ts.map +1 -0
- package/dist/sessions/store.js +70 -0
- package/dist/sessions/store.js.map +1 -0
- package/dist/sessions/transcript-events.d.ts +11 -0
- package/dist/sessions/transcript-events.d.ts.map +1 -0
- package/dist/sessions/transcript-events.js +40 -0
- package/dist/sessions/transcript-events.js.map +1 -0
- package/dist/shared/agent-session.d.ts +10 -0
- package/dist/shared/agent-session.d.ts.map +1 -0
- package/dist/shared/agent-session.js +33 -0
- package/dist/shared/agent-session.js.map +1 -0
- package/dist/shared/constants.d.ts +6 -0
- package/dist/shared/constants.d.ts.map +1 -0
- package/dist/shared/constants.js +17 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/shared/fs.d.ts +7 -0
- package/dist/shared/fs.d.ts.map +1 -0
- package/dist/shared/fs.js +14 -0
- package/dist/shared/fs.js.map +1 -0
- package/dist/shared/index.d.ts +4 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/skills/enablement.d.ts +10 -0
- package/dist/skills/enablement.d.ts.map +1 -0
- package/dist/skills/enablement.js +52 -0
- package/dist/skills/enablement.js.map +1 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +4 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/loader.d.ts +8 -0
- package/dist/skills/loader.d.ts.map +1 -0
- package/dist/skills/loader.js +8 -0
- package/dist/skills/loader.js.map +1 -0
- package/dist/skills/registry.d.ts +19 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/registry.js +106 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/utils/boolean.d.ts +6 -0
- package/dist/utils/boolean.d.ts.map +1 -0
- package/dist/utils/boolean.js +28 -0
- package/dist/utils/boolean.js.map +1 -0
- package/dist/utils/run-with-concurrency.d.ts +12 -0
- package/dist/utils/run-with-concurrency.d.ts.map +1 -0
- package/dist/utils/run-with-concurrency.js +40 -0
- package/dist/utils/run-with-concurrency.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +38 -0
- package/dist/utils.js.map +1 -0
- package/dist/workspace/index.d.ts +3 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/runner.d.ts +19 -0
- package/dist/workspace/runner.d.ts.map +1 -0
- package/dist/workspace/runner.js +491 -0
- package/dist/workspace/runner.js.map +1 -0
- package/dist/workspace/types.d.ts +37 -0
- package/dist/workspace/types.d.ts.map +1 -0
- package/dist/workspace/types.js +2 -0
- package/dist/workspace/types.js.map +1 -0
- package/dist/workspace/workspace.d.ts +12 -0
- package/dist/workspace/workspace.d.ts.map +1 -0
- package/dist/workspace/workspace.js +85 -0
- package/dist/workspace/workspace.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query expansion for FTS-only search mode.
|
|
3
|
+
*
|
|
4
|
+
* When no embedding provider is available, we fall back to FTS (full-text search).
|
|
5
|
+
* FTS works best with specific keywords, but users often ask conversational queries
|
|
6
|
+
* like "that thing we discussed yesterday" or "之前讨论的那个方案".
|
|
7
|
+
*
|
|
8
|
+
* This module extracts meaningful keywords from such queries to improve FTS results.
|
|
9
|
+
*/
|
|
10
|
+
// Common stop words that don't add search value
|
|
11
|
+
const STOP_WORDS_EN = new Set([
|
|
12
|
+
// Articles and determiners
|
|
13
|
+
"a",
|
|
14
|
+
"an",
|
|
15
|
+
"the",
|
|
16
|
+
"this",
|
|
17
|
+
"that",
|
|
18
|
+
"these",
|
|
19
|
+
"those",
|
|
20
|
+
// Pronouns
|
|
21
|
+
"i",
|
|
22
|
+
"me",
|
|
23
|
+
"my",
|
|
24
|
+
"we",
|
|
25
|
+
"our",
|
|
26
|
+
"you",
|
|
27
|
+
"your",
|
|
28
|
+
"he",
|
|
29
|
+
"she",
|
|
30
|
+
"it",
|
|
31
|
+
"they",
|
|
32
|
+
"them",
|
|
33
|
+
// Common verbs
|
|
34
|
+
"is",
|
|
35
|
+
"are",
|
|
36
|
+
"was",
|
|
37
|
+
"were",
|
|
38
|
+
"be",
|
|
39
|
+
"been",
|
|
40
|
+
"being",
|
|
41
|
+
"have",
|
|
42
|
+
"has",
|
|
43
|
+
"had",
|
|
44
|
+
"do",
|
|
45
|
+
"does",
|
|
46
|
+
"did",
|
|
47
|
+
"will",
|
|
48
|
+
"would",
|
|
49
|
+
"could",
|
|
50
|
+
"should",
|
|
51
|
+
"can",
|
|
52
|
+
"may",
|
|
53
|
+
"might",
|
|
54
|
+
// Prepositions
|
|
55
|
+
"in",
|
|
56
|
+
"on",
|
|
57
|
+
"at",
|
|
58
|
+
"to",
|
|
59
|
+
"for",
|
|
60
|
+
"of",
|
|
61
|
+
"with",
|
|
62
|
+
"by",
|
|
63
|
+
"from",
|
|
64
|
+
"about",
|
|
65
|
+
"into",
|
|
66
|
+
"through",
|
|
67
|
+
"during",
|
|
68
|
+
"before",
|
|
69
|
+
"after",
|
|
70
|
+
"above",
|
|
71
|
+
"below",
|
|
72
|
+
"between",
|
|
73
|
+
"under",
|
|
74
|
+
"over",
|
|
75
|
+
// Conjunctions
|
|
76
|
+
"and",
|
|
77
|
+
"or",
|
|
78
|
+
"but",
|
|
79
|
+
"if",
|
|
80
|
+
"then",
|
|
81
|
+
"because",
|
|
82
|
+
"as",
|
|
83
|
+
"while",
|
|
84
|
+
"when",
|
|
85
|
+
"where",
|
|
86
|
+
"what",
|
|
87
|
+
"which",
|
|
88
|
+
"who",
|
|
89
|
+
"how",
|
|
90
|
+
"why",
|
|
91
|
+
// Time references (vague, not useful for FTS)
|
|
92
|
+
"yesterday",
|
|
93
|
+
"today",
|
|
94
|
+
"tomorrow",
|
|
95
|
+
"earlier",
|
|
96
|
+
"later",
|
|
97
|
+
"recently",
|
|
98
|
+
"before",
|
|
99
|
+
"ago",
|
|
100
|
+
"just",
|
|
101
|
+
"now",
|
|
102
|
+
// Vague references
|
|
103
|
+
"thing",
|
|
104
|
+
"things",
|
|
105
|
+
"stuff",
|
|
106
|
+
"something",
|
|
107
|
+
"anything",
|
|
108
|
+
"everything",
|
|
109
|
+
"nothing",
|
|
110
|
+
// Question words
|
|
111
|
+
"please",
|
|
112
|
+
"help",
|
|
113
|
+
"find",
|
|
114
|
+
"show",
|
|
115
|
+
"get",
|
|
116
|
+
"tell",
|
|
117
|
+
"give",
|
|
118
|
+
]);
|
|
119
|
+
const STOP_WORDS_ES = new Set([
|
|
120
|
+
// Articles and determiners
|
|
121
|
+
"el",
|
|
122
|
+
"la",
|
|
123
|
+
"los",
|
|
124
|
+
"las",
|
|
125
|
+
"un",
|
|
126
|
+
"una",
|
|
127
|
+
"unos",
|
|
128
|
+
"unas",
|
|
129
|
+
"este",
|
|
130
|
+
"esta",
|
|
131
|
+
"ese",
|
|
132
|
+
"esa",
|
|
133
|
+
// Pronouns
|
|
134
|
+
"yo",
|
|
135
|
+
"me",
|
|
136
|
+
"mi",
|
|
137
|
+
"nosotros",
|
|
138
|
+
"nosotras",
|
|
139
|
+
"tu",
|
|
140
|
+
"tus",
|
|
141
|
+
"usted",
|
|
142
|
+
"ustedes",
|
|
143
|
+
"ellos",
|
|
144
|
+
"ellas",
|
|
145
|
+
// Prepositions and conjunctions
|
|
146
|
+
"de",
|
|
147
|
+
"del",
|
|
148
|
+
"a",
|
|
149
|
+
"en",
|
|
150
|
+
"con",
|
|
151
|
+
"por",
|
|
152
|
+
"para",
|
|
153
|
+
"sobre",
|
|
154
|
+
"entre",
|
|
155
|
+
"y",
|
|
156
|
+
"o",
|
|
157
|
+
"pero",
|
|
158
|
+
"si",
|
|
159
|
+
"porque",
|
|
160
|
+
"como",
|
|
161
|
+
// Common verbs / auxiliaries
|
|
162
|
+
"es",
|
|
163
|
+
"son",
|
|
164
|
+
"fue",
|
|
165
|
+
"fueron",
|
|
166
|
+
"ser",
|
|
167
|
+
"estar",
|
|
168
|
+
"haber",
|
|
169
|
+
"tener",
|
|
170
|
+
"hacer",
|
|
171
|
+
// Time references (vague)
|
|
172
|
+
"ayer",
|
|
173
|
+
"hoy",
|
|
174
|
+
"mañana",
|
|
175
|
+
"antes",
|
|
176
|
+
"despues",
|
|
177
|
+
"después",
|
|
178
|
+
"ahora",
|
|
179
|
+
"recientemente",
|
|
180
|
+
// Question/request words
|
|
181
|
+
"que",
|
|
182
|
+
"qué",
|
|
183
|
+
"cómo",
|
|
184
|
+
"cuando",
|
|
185
|
+
"cuándo",
|
|
186
|
+
"donde",
|
|
187
|
+
"dónde",
|
|
188
|
+
"porqué",
|
|
189
|
+
"favor",
|
|
190
|
+
"ayuda",
|
|
191
|
+
]);
|
|
192
|
+
const STOP_WORDS_PT = new Set([
|
|
193
|
+
// Articles and determiners
|
|
194
|
+
"o",
|
|
195
|
+
"a",
|
|
196
|
+
"os",
|
|
197
|
+
"as",
|
|
198
|
+
"um",
|
|
199
|
+
"uma",
|
|
200
|
+
"uns",
|
|
201
|
+
"umas",
|
|
202
|
+
"este",
|
|
203
|
+
"esta",
|
|
204
|
+
"esse",
|
|
205
|
+
"essa",
|
|
206
|
+
// Pronouns
|
|
207
|
+
"eu",
|
|
208
|
+
"me",
|
|
209
|
+
"meu",
|
|
210
|
+
"minha",
|
|
211
|
+
"nos",
|
|
212
|
+
"nós",
|
|
213
|
+
"você",
|
|
214
|
+
"vocês",
|
|
215
|
+
"ele",
|
|
216
|
+
"ela",
|
|
217
|
+
"eles",
|
|
218
|
+
"elas",
|
|
219
|
+
// Prepositions and conjunctions
|
|
220
|
+
"de",
|
|
221
|
+
"do",
|
|
222
|
+
"da",
|
|
223
|
+
"em",
|
|
224
|
+
"com",
|
|
225
|
+
"por",
|
|
226
|
+
"para",
|
|
227
|
+
"sobre",
|
|
228
|
+
"entre",
|
|
229
|
+
"e",
|
|
230
|
+
"ou",
|
|
231
|
+
"mas",
|
|
232
|
+
"se",
|
|
233
|
+
"porque",
|
|
234
|
+
"como",
|
|
235
|
+
// Common verbs / auxiliaries
|
|
236
|
+
"é",
|
|
237
|
+
"são",
|
|
238
|
+
"foi",
|
|
239
|
+
"foram",
|
|
240
|
+
"ser",
|
|
241
|
+
"estar",
|
|
242
|
+
"ter",
|
|
243
|
+
"fazer",
|
|
244
|
+
// Time references (vague)
|
|
245
|
+
"ontem",
|
|
246
|
+
"hoje",
|
|
247
|
+
"amanhã",
|
|
248
|
+
"antes",
|
|
249
|
+
"depois",
|
|
250
|
+
"agora",
|
|
251
|
+
"recentemente",
|
|
252
|
+
// Question/request words
|
|
253
|
+
"que",
|
|
254
|
+
"quê",
|
|
255
|
+
"quando",
|
|
256
|
+
"onde",
|
|
257
|
+
"porquê",
|
|
258
|
+
"favor",
|
|
259
|
+
"ajuda",
|
|
260
|
+
]);
|
|
261
|
+
const STOP_WORDS_AR = new Set([
|
|
262
|
+
// Articles and connectors
|
|
263
|
+
"ال",
|
|
264
|
+
"و",
|
|
265
|
+
"أو",
|
|
266
|
+
"لكن",
|
|
267
|
+
"ثم",
|
|
268
|
+
"بل",
|
|
269
|
+
// Pronouns / references
|
|
270
|
+
"أنا",
|
|
271
|
+
"نحن",
|
|
272
|
+
"هو",
|
|
273
|
+
"هي",
|
|
274
|
+
"هم",
|
|
275
|
+
"هذا",
|
|
276
|
+
"هذه",
|
|
277
|
+
"ذلك",
|
|
278
|
+
"تلك",
|
|
279
|
+
"هنا",
|
|
280
|
+
"هناك",
|
|
281
|
+
// Common prepositions
|
|
282
|
+
"من",
|
|
283
|
+
"إلى",
|
|
284
|
+
"الى",
|
|
285
|
+
"في",
|
|
286
|
+
"على",
|
|
287
|
+
"عن",
|
|
288
|
+
"مع",
|
|
289
|
+
"بين",
|
|
290
|
+
"ل",
|
|
291
|
+
"ب",
|
|
292
|
+
"ك",
|
|
293
|
+
// Common auxiliaries / vague verbs
|
|
294
|
+
"كان",
|
|
295
|
+
"كانت",
|
|
296
|
+
"يكون",
|
|
297
|
+
"تكون",
|
|
298
|
+
"صار",
|
|
299
|
+
"أصبح",
|
|
300
|
+
"يمكن",
|
|
301
|
+
"ممكن",
|
|
302
|
+
// Time references (vague)
|
|
303
|
+
"بالأمس",
|
|
304
|
+
"امس",
|
|
305
|
+
"اليوم",
|
|
306
|
+
"غدا",
|
|
307
|
+
"الآن",
|
|
308
|
+
"قبل",
|
|
309
|
+
"بعد",
|
|
310
|
+
"مؤخرا",
|
|
311
|
+
// Question/request words
|
|
312
|
+
"لماذا",
|
|
313
|
+
"كيف",
|
|
314
|
+
"ماذا",
|
|
315
|
+
"متى",
|
|
316
|
+
"أين",
|
|
317
|
+
"هل",
|
|
318
|
+
"من فضلك",
|
|
319
|
+
"فضلا",
|
|
320
|
+
"ساعد",
|
|
321
|
+
]);
|
|
322
|
+
const STOP_WORDS_KO = new Set([
|
|
323
|
+
// Particles (조사)
|
|
324
|
+
"은",
|
|
325
|
+
"는",
|
|
326
|
+
"이",
|
|
327
|
+
"가",
|
|
328
|
+
"을",
|
|
329
|
+
"를",
|
|
330
|
+
"의",
|
|
331
|
+
"에",
|
|
332
|
+
"에서",
|
|
333
|
+
"로",
|
|
334
|
+
"으로",
|
|
335
|
+
"와",
|
|
336
|
+
"과",
|
|
337
|
+
"도",
|
|
338
|
+
"만",
|
|
339
|
+
"까지",
|
|
340
|
+
"부터",
|
|
341
|
+
"한테",
|
|
342
|
+
"에게",
|
|
343
|
+
"께",
|
|
344
|
+
"처럼",
|
|
345
|
+
"같이",
|
|
346
|
+
"보다",
|
|
347
|
+
"마다",
|
|
348
|
+
"밖에",
|
|
349
|
+
"대로",
|
|
350
|
+
// Pronouns (대명사)
|
|
351
|
+
"나",
|
|
352
|
+
"나는",
|
|
353
|
+
"내가",
|
|
354
|
+
"나를",
|
|
355
|
+
"너",
|
|
356
|
+
"우리",
|
|
357
|
+
"저",
|
|
358
|
+
"저희",
|
|
359
|
+
"그",
|
|
360
|
+
"그녀",
|
|
361
|
+
"그들",
|
|
362
|
+
"이것",
|
|
363
|
+
"저것",
|
|
364
|
+
"그것",
|
|
365
|
+
"여기",
|
|
366
|
+
"저기",
|
|
367
|
+
"거기",
|
|
368
|
+
// Common verbs / auxiliaries (일반 동사/보조 동사)
|
|
369
|
+
"있다",
|
|
370
|
+
"없다",
|
|
371
|
+
"하다",
|
|
372
|
+
"되다",
|
|
373
|
+
"이다",
|
|
374
|
+
"아니다",
|
|
375
|
+
"보다",
|
|
376
|
+
"주다",
|
|
377
|
+
"오다",
|
|
378
|
+
"가다",
|
|
379
|
+
// Nouns (의존 명사 / vague)
|
|
380
|
+
"것",
|
|
381
|
+
"거",
|
|
382
|
+
"등",
|
|
383
|
+
"수",
|
|
384
|
+
"때",
|
|
385
|
+
"곳",
|
|
386
|
+
"중",
|
|
387
|
+
"분",
|
|
388
|
+
// Adverbs
|
|
389
|
+
"잘",
|
|
390
|
+
"더",
|
|
391
|
+
"또",
|
|
392
|
+
"매우",
|
|
393
|
+
"정말",
|
|
394
|
+
"아주",
|
|
395
|
+
"많이",
|
|
396
|
+
"너무",
|
|
397
|
+
"좀",
|
|
398
|
+
// Conjunctions
|
|
399
|
+
"그리고",
|
|
400
|
+
"하지만",
|
|
401
|
+
"그래서",
|
|
402
|
+
"그런데",
|
|
403
|
+
"그러나",
|
|
404
|
+
"또는",
|
|
405
|
+
"그러면",
|
|
406
|
+
// Question words
|
|
407
|
+
"왜",
|
|
408
|
+
"어떻게",
|
|
409
|
+
"뭐",
|
|
410
|
+
"언제",
|
|
411
|
+
"어디",
|
|
412
|
+
"누구",
|
|
413
|
+
"무엇",
|
|
414
|
+
"어떤",
|
|
415
|
+
// Time (vague)
|
|
416
|
+
"어제",
|
|
417
|
+
"오늘",
|
|
418
|
+
"내일",
|
|
419
|
+
"최근",
|
|
420
|
+
"지금",
|
|
421
|
+
"아까",
|
|
422
|
+
"나중",
|
|
423
|
+
"전에",
|
|
424
|
+
// Request words
|
|
425
|
+
"제발",
|
|
426
|
+
"부탁",
|
|
427
|
+
]);
|
|
428
|
+
// Common Korean trailing particles to strip from words for tokenization
|
|
429
|
+
// Sorted by descending length so longest-match-first is guaranteed.
|
|
430
|
+
const KO_TRAILING_PARTICLES = [
|
|
431
|
+
"에서",
|
|
432
|
+
"으로",
|
|
433
|
+
"에게",
|
|
434
|
+
"한테",
|
|
435
|
+
"처럼",
|
|
436
|
+
"같이",
|
|
437
|
+
"보다",
|
|
438
|
+
"까지",
|
|
439
|
+
"부터",
|
|
440
|
+
"마다",
|
|
441
|
+
"밖에",
|
|
442
|
+
"대로",
|
|
443
|
+
"은",
|
|
444
|
+
"는",
|
|
445
|
+
"이",
|
|
446
|
+
"가",
|
|
447
|
+
"을",
|
|
448
|
+
"를",
|
|
449
|
+
"의",
|
|
450
|
+
"에",
|
|
451
|
+
"로",
|
|
452
|
+
"와",
|
|
453
|
+
"과",
|
|
454
|
+
"도",
|
|
455
|
+
"만",
|
|
456
|
+
].toSorted((a, b) => b.length - a.length);
|
|
457
|
+
function stripKoreanTrailingParticle(token) {
|
|
458
|
+
for (const particle of KO_TRAILING_PARTICLES) {
|
|
459
|
+
if (token.length > particle.length && token.endsWith(particle)) {
|
|
460
|
+
return token.slice(0, -particle.length);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
function isUsefulKoreanStem(stem) {
|
|
466
|
+
// Prevent bogus one-syllable stems from words like "논의" -> "논".
|
|
467
|
+
if (/[\uac00-\ud7af]/.test(stem)) {
|
|
468
|
+
return stem.length >= 2;
|
|
469
|
+
}
|
|
470
|
+
// Keep stripped ASCII stems for mixed tokens like "API를" -> "api".
|
|
471
|
+
return /^[a-z0-9_]+$/i.test(stem);
|
|
472
|
+
}
|
|
473
|
+
const STOP_WORDS_JA = new Set([
|
|
474
|
+
// Pronouns and references
|
|
475
|
+
"これ",
|
|
476
|
+
"それ",
|
|
477
|
+
"あれ",
|
|
478
|
+
"この",
|
|
479
|
+
"その",
|
|
480
|
+
"あの",
|
|
481
|
+
"ここ",
|
|
482
|
+
"そこ",
|
|
483
|
+
"あそこ",
|
|
484
|
+
// Common auxiliaries / vague verbs
|
|
485
|
+
"する",
|
|
486
|
+
"した",
|
|
487
|
+
"して",
|
|
488
|
+
"です",
|
|
489
|
+
"ます",
|
|
490
|
+
"いる",
|
|
491
|
+
"ある",
|
|
492
|
+
"なる",
|
|
493
|
+
"できる",
|
|
494
|
+
// Particles / connectors
|
|
495
|
+
"の",
|
|
496
|
+
"こと",
|
|
497
|
+
"もの",
|
|
498
|
+
"ため",
|
|
499
|
+
"そして",
|
|
500
|
+
"しかし",
|
|
501
|
+
"また",
|
|
502
|
+
"でも",
|
|
503
|
+
"から",
|
|
504
|
+
"まで",
|
|
505
|
+
"より",
|
|
506
|
+
"だけ",
|
|
507
|
+
// Question words
|
|
508
|
+
"なぜ",
|
|
509
|
+
"どう",
|
|
510
|
+
"何",
|
|
511
|
+
"いつ",
|
|
512
|
+
"どこ",
|
|
513
|
+
"誰",
|
|
514
|
+
"どれ",
|
|
515
|
+
// Time (vague)
|
|
516
|
+
"昨日",
|
|
517
|
+
"今日",
|
|
518
|
+
"明日",
|
|
519
|
+
"最近",
|
|
520
|
+
"今",
|
|
521
|
+
"さっき",
|
|
522
|
+
"前",
|
|
523
|
+
"後",
|
|
524
|
+
]);
|
|
525
|
+
const STOP_WORDS_ZH = new Set([
|
|
526
|
+
// Pronouns
|
|
527
|
+
"我",
|
|
528
|
+
"我们",
|
|
529
|
+
"你",
|
|
530
|
+
"你们",
|
|
531
|
+
"他",
|
|
532
|
+
"她",
|
|
533
|
+
"它",
|
|
534
|
+
"他们",
|
|
535
|
+
"这",
|
|
536
|
+
"那",
|
|
537
|
+
"这个",
|
|
538
|
+
"那个",
|
|
539
|
+
"这些",
|
|
540
|
+
"那些",
|
|
541
|
+
// Auxiliary words
|
|
542
|
+
"的",
|
|
543
|
+
"了",
|
|
544
|
+
"着",
|
|
545
|
+
"过",
|
|
546
|
+
"得",
|
|
547
|
+
"地",
|
|
548
|
+
"吗",
|
|
549
|
+
"呢",
|
|
550
|
+
"吧",
|
|
551
|
+
"啊",
|
|
552
|
+
"呀",
|
|
553
|
+
"嘛",
|
|
554
|
+
"啦",
|
|
555
|
+
// Verbs (common, vague)
|
|
556
|
+
"是",
|
|
557
|
+
"有",
|
|
558
|
+
"在",
|
|
559
|
+
"被",
|
|
560
|
+
"把",
|
|
561
|
+
"给",
|
|
562
|
+
"让",
|
|
563
|
+
"用",
|
|
564
|
+
"到",
|
|
565
|
+
"去",
|
|
566
|
+
"来",
|
|
567
|
+
"做",
|
|
568
|
+
"说",
|
|
569
|
+
"看",
|
|
570
|
+
"找",
|
|
571
|
+
"想",
|
|
572
|
+
"要",
|
|
573
|
+
"能",
|
|
574
|
+
"会",
|
|
575
|
+
"可以",
|
|
576
|
+
// Prepositions and conjunctions
|
|
577
|
+
"和",
|
|
578
|
+
"与",
|
|
579
|
+
"或",
|
|
580
|
+
"但",
|
|
581
|
+
"但是",
|
|
582
|
+
"因为",
|
|
583
|
+
"所以",
|
|
584
|
+
"如果",
|
|
585
|
+
"虽然",
|
|
586
|
+
"而",
|
|
587
|
+
"也",
|
|
588
|
+
"都",
|
|
589
|
+
"就",
|
|
590
|
+
"还",
|
|
591
|
+
"又",
|
|
592
|
+
"再",
|
|
593
|
+
"才",
|
|
594
|
+
"只",
|
|
595
|
+
// Time (vague)
|
|
596
|
+
"之前",
|
|
597
|
+
"以前",
|
|
598
|
+
"之后",
|
|
599
|
+
"以后",
|
|
600
|
+
"刚才",
|
|
601
|
+
"现在",
|
|
602
|
+
"昨天",
|
|
603
|
+
"今天",
|
|
604
|
+
"明天",
|
|
605
|
+
"最近",
|
|
606
|
+
// Vague references
|
|
607
|
+
"东西",
|
|
608
|
+
"事情",
|
|
609
|
+
"事",
|
|
610
|
+
"什么",
|
|
611
|
+
"哪个",
|
|
612
|
+
"哪些",
|
|
613
|
+
"怎么",
|
|
614
|
+
"为什么",
|
|
615
|
+
"多少",
|
|
616
|
+
// Question/request words
|
|
617
|
+
"请",
|
|
618
|
+
"帮",
|
|
619
|
+
"帮忙",
|
|
620
|
+
"告诉",
|
|
621
|
+
]);
|
|
622
|
+
export function isQueryStopWordToken(token) {
|
|
623
|
+
return (STOP_WORDS_EN.has(token) ||
|
|
624
|
+
STOP_WORDS_ES.has(token) ||
|
|
625
|
+
STOP_WORDS_PT.has(token) ||
|
|
626
|
+
STOP_WORDS_AR.has(token) ||
|
|
627
|
+
STOP_WORDS_ZH.has(token) ||
|
|
628
|
+
STOP_WORDS_KO.has(token) ||
|
|
629
|
+
STOP_WORDS_JA.has(token));
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Check if a token looks like a meaningful keyword.
|
|
633
|
+
* Returns false for short tokens, numbers-only, etc.
|
|
634
|
+
*/
|
|
635
|
+
function isValidKeyword(token) {
|
|
636
|
+
if (!token || token.length === 0) {
|
|
637
|
+
return false;
|
|
638
|
+
}
|
|
639
|
+
// Skip very short English words (likely stop words or fragments)
|
|
640
|
+
if (/^[a-zA-Z]+$/.test(token) && token.length < 3) {
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
// Skip pure numbers (not useful for semantic search)
|
|
644
|
+
if (/^\d+$/.test(token)) {
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
// Skip tokens that are all punctuation
|
|
648
|
+
if (/^[\p{P}\p{S}]+$/u.test(token)) {
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Simple tokenizer that handles English, Chinese, Korean, and Japanese text.
|
|
655
|
+
* For Chinese, we do character-based splitting since we don't have a proper segmenter.
|
|
656
|
+
* For English, we split on whitespace and punctuation.
|
|
657
|
+
*/
|
|
658
|
+
function tokenize(text) {
|
|
659
|
+
const tokens = [];
|
|
660
|
+
const normalized = text.toLowerCase().trim();
|
|
661
|
+
// Split into segments (English words, Chinese character sequences, etc.)
|
|
662
|
+
const segments = normalized.split(/[\s\p{P}]+/u).filter(Boolean);
|
|
663
|
+
for (const segment of segments) {
|
|
664
|
+
// Japanese text often mixes scripts (kanji/kana/ASCII) without spaces.
|
|
665
|
+
// Extract script-specific chunks so technical terms like "API" / "バグ" are retained.
|
|
666
|
+
if (/[\u3040-\u30ff]/.test(segment)) {
|
|
667
|
+
const jpParts = segment.match(/[a-z0-9_]+|[\u30a0-\u30ffー]+|[\u4e00-\u9fff]+|[\u3040-\u309f]{2,}/g) ?? [];
|
|
668
|
+
for (const part of jpParts) {
|
|
669
|
+
if (/^[\u4e00-\u9fff]+$/.test(part)) {
|
|
670
|
+
tokens.push(part);
|
|
671
|
+
for (let i = 0; i < part.length - 1; i++) {
|
|
672
|
+
tokens.push(part[i] + part[i + 1]);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
tokens.push(part);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
else if (/[\u4e00-\u9fff]/.test(segment)) {
|
|
681
|
+
// Check if segment contains CJK characters (Chinese)
|
|
682
|
+
// For Chinese, extract character n-grams (unigrams and bigrams)
|
|
683
|
+
const chars = Array.from(segment).filter((c) => /[\u4e00-\u9fff]/.test(c));
|
|
684
|
+
// Add individual characters
|
|
685
|
+
tokens.push(...chars);
|
|
686
|
+
// Add bigrams for better phrase matching
|
|
687
|
+
for (let i = 0; i < chars.length - 1; i++) {
|
|
688
|
+
tokens.push(chars[i] + chars[i + 1]);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
else if (/[\uac00-\ud7af\u3131-\u3163]/.test(segment)) {
|
|
692
|
+
// For Korean (Hangul syllables and jamo), keep the word as-is unless it is
|
|
693
|
+
// effectively a stop word once trailing particles are removed.
|
|
694
|
+
const stem = stripKoreanTrailingParticle(segment);
|
|
695
|
+
const stemIsStopWord = stem !== null && STOP_WORDS_KO.has(stem);
|
|
696
|
+
if (!STOP_WORDS_KO.has(segment) && !stemIsStopWord) {
|
|
697
|
+
tokens.push(segment);
|
|
698
|
+
}
|
|
699
|
+
// Also emit particle-stripped stems when they are useful keywords.
|
|
700
|
+
if (stem && !STOP_WORDS_KO.has(stem) && isUsefulKoreanStem(stem)) {
|
|
701
|
+
tokens.push(stem);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
// For non-CJK, keep as single token
|
|
706
|
+
tokens.push(segment);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return tokens;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Extract keywords from a conversational query for FTS search.
|
|
713
|
+
*
|
|
714
|
+
* Examples:
|
|
715
|
+
* - "that thing we discussed about the API" → ["discussed", "API"]
|
|
716
|
+
* - "之前讨论的那个方案" → ["讨论", "方案"]
|
|
717
|
+
* - "what was the solution for the bug" → ["solution", "bug"]
|
|
718
|
+
*/
|
|
719
|
+
export function extractKeywords(query) {
|
|
720
|
+
const tokens = tokenize(query);
|
|
721
|
+
const keywords = [];
|
|
722
|
+
const seen = new Set();
|
|
723
|
+
for (const token of tokens) {
|
|
724
|
+
// Skip stop words
|
|
725
|
+
if (isQueryStopWordToken(token)) {
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
// Skip invalid keywords
|
|
729
|
+
if (!isValidKeyword(token)) {
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
// Skip duplicates
|
|
733
|
+
if (seen.has(token)) {
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
seen.add(token);
|
|
737
|
+
keywords.push(token);
|
|
738
|
+
}
|
|
739
|
+
return keywords;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Expand a query for FTS search.
|
|
743
|
+
* Returns both the original query and extracted keywords for OR-matching.
|
|
744
|
+
*
|
|
745
|
+
* @param query - User's original query
|
|
746
|
+
* @returns Object with original query and extracted keywords
|
|
747
|
+
*/
|
|
748
|
+
export function expandQueryForFts(query) {
|
|
749
|
+
const original = query.trim();
|
|
750
|
+
const keywords = extractKeywords(original);
|
|
751
|
+
// Build expanded query: original terms OR extracted keywords
|
|
752
|
+
// This ensures both exact matches and keyword matches are found
|
|
753
|
+
const expanded = keywords.length > 0 ? `${original} OR ${keywords.join(" OR ")}` : original;
|
|
754
|
+
return { original, keywords, expanded };
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Expand query with optional LLM assistance.
|
|
758
|
+
* Falls back to local extraction if LLM is unavailable or fails.
|
|
759
|
+
*/
|
|
760
|
+
export async function expandQueryWithLlm(query, llmExpander) {
|
|
761
|
+
// If LLM expander is provided, try it first
|
|
762
|
+
if (llmExpander) {
|
|
763
|
+
try {
|
|
764
|
+
const llmKeywords = await llmExpander(query);
|
|
765
|
+
if (llmKeywords.length > 0) {
|
|
766
|
+
return llmKeywords;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
catch {
|
|
770
|
+
// LLM failed, fall back to local extraction
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
// Fall back to local keyword extraction
|
|
774
|
+
return extractKeywords(query);
|
|
775
|
+
}
|
|
776
|
+
//# sourceMappingURL=query-expansion.js.map
|