@o-lang/semantic-doc-search 1.0.24 → 1.0.25
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 +1 -1
- package/src/index.js +23 -12
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -253,20 +253,31 @@ async function docSearchResolver(action, context) {
|
|
|
253
253
|
const match = action.match(/"(.*)"|'(.*)'/);
|
|
254
254
|
const query = match ? match[1] || match[2] : action.replace("Ask doc-search", "").trim();
|
|
255
255
|
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
256
|
+
// Internal settings (hidden from workflow)
|
|
257
|
+
const INTERNAL_TOPK = 5; // how many nearest chunks to fetch
|
|
258
|
+
const INTERNAL_MINSCORE = 0.75; // similarity threshold
|
|
259
|
+
|
|
260
|
+
// Perform the search
|
|
261
|
+
const results = await performDocQA(query, { ...context, topK: INTERNAL_TOPK, minScore: INTERNAL_MINSCORE });
|
|
262
|
+
|
|
263
|
+
// If no results meet the threshold, fallback to the best match
|
|
264
|
+
let finalResults;
|
|
265
|
+
if (!results || results.meta.matches === 0) {
|
|
266
|
+
const fallback = await performDocQA(query, { ...context, topK: 1, minScore: 0 });
|
|
267
|
+
finalResults = fallback;
|
|
268
|
+
} else {
|
|
269
|
+
finalResults = results;
|
|
270
|
+
}
|
|
265
271
|
|
|
266
|
-
//
|
|
267
|
-
|
|
272
|
+
// Ensure LLM always receives text
|
|
273
|
+
if (!finalResults || !finalResults.text || finalResults.text.trim() === "") {
|
|
274
|
+
return {
|
|
275
|
+
text: `No relevant information found for "${query}".`,
|
|
276
|
+
meta: { matches: 0 }
|
|
277
|
+
};
|
|
278
|
+
}
|
|
268
279
|
|
|
269
|
-
return
|
|
280
|
+
return finalResults;
|
|
270
281
|
}
|
|
271
282
|
|
|
272
283
|
docSearchResolver.resolverName = "doc-search";
|