Paginate Vector Search Results
I'm allowing users to search for posts by entering a term and returning the vector search results. How can I paginate these results so that as they scroll down, more are loaded? I'm following the search pattern used in (https://github.com/get-convex/convex-demos/tree/main/vector-search)
I've posted what I currently have implemented on my client and server side.
GitHub
convex-demos/vector-search at main · get-convex/convex-demos
Demo apps built on Convex. Contribute to get-convex/convex-demos development by creating an account on GitHub.
4 Replies
Here is the fetchResults I'm calling from similarPosts
Two ideas:
1. Just return the full list and show/ fetch batches from the client
2. Write the results for many (1k?) matching documents to a table, then have a query that serves some subset of the matching documents for each page. You could pass up how many you want & the offset into that list. It'd be a stale list, but allow you to only fetch some documents at a time, just storing the long list of IDs in the table
Going with your first option how would I show/fetch batches after getting the entire list of results? I guess I'm just confused about the implementation of it since I'm not sure where the results "live" and can be fetched from while the user scrolls through pages
For option 1, you fetch the whole list of ids to the client, it can request batches of ids at a time. So the client holds the results. (2) would be holding the results in the server. a third option would be to keep making the same request, but passing up the last previously fetched ID for where to start the next batch of results. So it fetches 10 results the first time, 20 the second but only returns the 10 after the last found ID, then fetches 30 and returns 10, etc