typesense / typesense/typesense
Snippeting is slow: `highlight_fields` with long document causes timeouts
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 26.6k
- Forks
- 973
- Avg merge
- 18h 45m
- Merged PRs (30d)
- 4
Description
Issue
We have a Typesense cluster with 1.4 Million documents (hosted on Typesense Cloud), some of which have very large content fields (500+KB, see attached examples).
When retrieving results, we sometimes get timeout errors after 7 seconds, which we have pin-pointed to be caused by including "content" in the highlight_fields parameter. If we remove "content" from this field, the queries are quite fast—usually below 1s.
search-examples-request.json
search-examples-response.json
Expected behavior
I'd expect the snippeting/highlighting to not cause such a significant slowness. We already have increased the timeout, but 7s is not even enough in some cases.
Further context
Our use case involves to search related documents which backlink to the one the user is currently viewing. For this we have a refs field, which we filter on to limit the results to all backlinking docs. In addition to the filter on the refs field, the example above has the query "Ra 2015/18/0220" (not visible in the UI screenshot, but in the search-examples-response.json), which will show a snippet where the current document is referenced exactly in the one that backlinks to it.
Example with highlighting (different document), here you can see that the current document "§ 170 StPO" is highlighted in the results:
Example without highlighting, here just a generic snippet is shown, which is not helpful for users:
Version Info
Typesense Version: 27.1
JS SDK version: 1.8.2
Not using the the Instantsearch intergration, fetching via React Server Components (React v19)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the timeout with the attached search-examples-request.json and the long content field, comparing requests with and without content in highlight_fields. Investigate the snippeting/highlighting path and use the expected highlighted backlink snippet, without multi-second timeouts, as the completion criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- performance, search
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100