#community-help

Typesense Pagination and Expensive Querying Concerns

TLDR Michal inquired about cursor pagination and caching in Typesense. Kishore Nallan provided reasons for their absence and discussed improvements for range filter performance in the next release.

Powered by Struct AI
18
8mo
Solved
Join the chat
Feb 08, 2023 (8 months ago)
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
11:17 AM
Hi, just out of curiosity, why is there no cursor pagination in Typesense?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:20 AM
Much harder to pull off because cursor requires having a field whose value is static. In search we have to compute a text match score based on overlap of query tokens with the record. So there is no static score within a record to base the cursor on. Also, it requires having some kind of snapshot view of the data to retain consistency across pagination.
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
01:08 PM
Thanks. That makes perfect sense but why is the usage of snapshot or cache not desirable in this situation?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:13 PM
We could technically cache the result ids on which pagination happens, but the on-disk data which actually stores the content could change due to updates between pagination. So the results might look odd if a keyword on a record that's fetched was actually removed in an interim update.
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
01:26 PM
If we cache complete records instead of just IDs, would it be a waste of resources as people typically don't go beyond the first page?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:28 PM
Yes correct and actual data will be too large to store in memory anyway. May I know what problem you are facing?
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
01:31 PM
I am using Firestore as the primary database but it’s not possible to do a full-text search or expensive querying in Firestore. Typesense seems like a perfect solution for the full text search but expensive querying would require some kind of caching solution.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:33 PM
What do you mean by expensive querying?
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
01:35 PM
A geoquery combined with multiple range filters on different fields
01:39
Michal
01:39 PM
In Firestore it’s not possible to create a query that there is no index for
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:57 PM
We've work planned to improve range filter performance for next release.
01:59
Kishore Nallan
01:59 PM
Where does cursor fit into this?
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
02:06 PM
The offset pagination is more expensive to run especially after the user goes past multiple pages
02:10
Michal
02:10 PM
What if we cache just enough data to display the results without index information
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:11 PM
Typesense as a search engine is optimised for providing top results from a large set. Deep pagination is a problem for search. Even Google limits to top 10-20 pages for the same reason.
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
02:30 PM
Referring to your answer that the actual data will be too large to store in memory anyway - what if we cache records without the indexed text?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:31 PM
So that we can discuss specifics can you please DM an actual heavy query and what response time you see?
Michal
Photo of md5-2896e0db2aac6aab7bf74bc925c6564b
Michal
02:36 PM
I haven’t implemented the query yet. To be honest I am so used to Firestore that I am just unnecessary pre-optimizing and wondering how would this query behave at scale