feat: add structured content extraction and batch embedding optimization to highlight()
Fix highlight() hanging on structured text input by addressing 3 root causes:
1. embedBatch() now uses native WASM batch API (single forward pass instead
of N individual embed() calls via Promise.all)
2. highlight() auto-detects content type (plain text, rich-text JSON, HTML,
Markdown) and extracts meaningful text segments. Supports TipTap, Slate.js,
Lexical, Draft.js, and Quill Delta formats. New contentType hint and
contentExtractor callback for custom parsers.
3. Semantic matching phase has 10s timeout - falls back to text-only matches
instead of hanging indefinitely.
Also fixes extractTextContent() array check: uses type-based detection
(typeof data[0] === 'number') instead of length-based (data.length > 10)
so arrays of objects are properly indexed for text search.
New types: ContentType, ContentCategory, ExtractedSegment
New fields: HighlightParams.contentType, HighlightParams.contentExtractor,
Highlight.contentCategory
This commit is contained in:
parent
2b901974ed
commit
cca1cd8ce2
12 changed files with 1341 additions and 37 deletions
|
|
@ -412,6 +412,13 @@ const results = await brain.find({ query: 'David Smith' })
|
|||
await brain.find({ query: 'exact match', searchMode: 'text' }) // Text only
|
||||
await brain.find({ query: 'AI concepts', searchMode: 'semantic' }) // Semantic only
|
||||
await brain.find({ query: 'hybrid', hybridAlpha: 0.3 }) // Custom weighting
|
||||
|
||||
// Highlight structured content (v7.8.0) — plain text, JSON, HTML, Markdown
|
||||
const highlights = await brain.highlight({
|
||||
query: 'warrior',
|
||||
text: entity.data // Auto-detects TipTap, Slate, Lexical, HTML, Markdown
|
||||
})
|
||||
// Each highlight has: text, score, position, matchType, contentCategory
|
||||
```
|
||||
|
||||
**→ [Hybrid Search Documentation](docs/api/README.md#hybrid-search-v770)**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue