@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +23 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o-lang/semantic-doc-search",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "O-lang Semantic Document Search Resolver with hybrid search, embeddings, rerank, and streaming.",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
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
- // Optional: extract topK and minScore if provided in action, e.g. "Ask doc-search 'Vacation policy' topK=3 minScore=0.8"
257
- let topK = 5;
258
- let minScore = 0.75;
259
-
260
- const topKMatch = action.match(/topK\s*=\s*(\d+)/i);
261
- if (topKMatch) topK = parseInt(topKMatch[1], 10);
262
-
263
- const minScoreMatch = action.match(/minScore\s*=\s*(0?\.\d+|1(\.0)?)/i);
264
- if (minScoreMatch) minScore = parseFloat(minScoreMatch[1]);
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
- // Pass these into context for hybrid search
267
- const searchContext = { ...context, topK, minScore };
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 performDocQA(query, searchContext);
280
+ return finalResults;
270
281
  }
271
282
 
272
283
  docSearchResolver.resolverName = "doc-search";