fix: extraction, multi-hop traversal, and aggregate result shape (BR-ADV-FEATURES-BUN)

Three advanced-API correctness fixes, all reproducible on Node (not Bun-specific):

- Entity/concept extraction returned []. SmartExtractor combined agreeing signals
  with a weighted sum compared against an absolute 0.60 gate, so a confident
  low-weight signal lost selection to a mediocre high-weight one that then failed
  the gate, dropping the whole result. Select and gate on a normalized weighted
  average instead. The public `confidence` option now controls the threshold (was
  a dead hardcoded 0.60), and the embedding-signal timeout is raised 100ms -> 2000ms
  so the neural signal is not silently dropped on slower runtimes.

- Multi-hop find({ connected }) returned only the 1-hop neighbour. executeGraphSearch
  ignored depth/via; it now delegates to the depth-aware neighbors() BFS.

- find({ aggregate }) hid groupKey/metrics/count under .metadata, so callers
  expecting AggregateResult saw empty rows. Expose those fields at the top level.

Adds real-embedding regression tests in tests/integration/advanced-apis-regression.test.ts.
This commit is contained in:
David Snelling 2026-05-26 11:32:46 -07:00
parent 07754d135a
commit 0a9d1d9a17
8 changed files with 297 additions and 74 deletions

View file

@ -140,14 +140,17 @@ export class NeuralEntityExtractor {
// Step 2: Classify each candidate using SmartExtractor
for (const candidate of candidates) {
// Use SmartExtractor for unified neural + rule-based classification
// Use SmartExtractor for unified neural + rule-based classification.
// Pass the caller's threshold through so `confidence` actually controls the gate
// (previously SmartExtractor applied a hardcoded 0.60 floor, so a low confidence
// option had no loosening effect).
const classification = await this.smartExtractor.extract(candidate.text, {
definition: candidate.context,
allTerms: [candidate.text, candidate.context]
})
}, minConfidence)
// Skip if SmartExtractor returns null (low confidence) or below threshold
if (!classification || classification.confidence < minConfidence) {
// SmartExtractor already gates at minConfidence; this guards against null only.
if (!classification) {
continue
}