This message was deleted.
# community-help
s
This message was deleted.
k
šŸ‘‹ 10 seconds per document is too long. This is a newer model so I have not used it and might have some issues.. can you try with e5-small-v2?
e
Sure, I'll spin up a new cluster and get back to you tomorrow
šŸ‘ 1
I'm having much more success with
e5-small-v2
. I can import 500 products in 2min 45s, which seems reasonable: 270ms per document. Attempting to add the same batch on the same cluster with
gte-small
has totally locked up the cluster (mostly getting timeouts or 504 errors just using the Typesense Cloud dashboard). Looks like it's come good after 10min, so about 1.2s per document. I guess
gte-small
is just super slow? I'll push ahead with
e5-small-v2
and see how it goes for semantic search. Just getting back to my other question, how would a HA cluster react while the embeddings are being generated? Would it still lock up and stop serving requests or does only one server handle the import? What if my code sends multiple batches of documents simultaneously? It's alright having the import process take 10-20min or longer as long as search requests can still be served for that time.
k
I'm not sure why
gte-small
is so slow.
how would a HA cluster react while the embeddings are being generated? Would it still lock up and stop serving requests or does only one server handle the import? What if my code sends multiple batches of documents simultaneously?
In a HA cluster the embedding will be generated on all the 3 nodes independently. For remote embedding (like OpenAI) the embedding requests are forwarded to a single node though (leader) because of the API costs involved in duplication of requests. The reads and write are interleaved during import so you will experience some additional query latency.
e
Thanks Kishore. I might spin up a HA cluster and see how it performs while importing. I'm using the JS client to import batches of documents to Typesense. Embeddings add an extra frustration here, because the HTTP request doesn't return until all of the embeddings are processed - potentially 10min or more. Such long response times make the TS client significantly more difficult to develop for and have the potential for timing out, especially since I'm running it on "serverless" infrastructure that is memory and CPU-time limited. I could probably fire the request, wait a bit and then drop it but getting the success/fail response for each document is desirable. I'm not sure if it is practical but I'd love to see Typesense able to accept batch imports like this: • Attempt to insert all the documents into the index without embeddings • Return the usual success/fail HTTP response • Then progressively generate embeddings in the background This background processing of embeddings could be optionally enabled by a parameter on the batch import endpoint. If that's possible it would give the best of both worlds and keep the JS API really simple and easy to use even for long-running text embedding generation.
k
Thanks for the feedback. Is there a reason why you can't send smaller batches of documents into typesense?
e
I'm working with a fairly limited ecommerce system that makes it hard to sync incremental updates to products. To keep the search index current I sometimes need to re-index everything, so a few thousand records (although I'd like the system to scale to 100x that capacity to use on other websites). At the moment these are streamed from the ecommerce system to Typesense on a serverless platform. Read a batch of 500 records, prepare the search data, push to Typesense and wait, then repeat. Even if I sent smaller batches to Typesense, it's the same total amount of data and the later batches are still going to take a long time to return. Plus then the data is piling up in memory instead of being flushed out after each batch so I'll end up memory-limited. If someone wanted to use a big model like gte-large I can see it getting really impractical to do any batch imports. Even a relatively small file could lead to an extremely long response time. It just seems more logical to have an API endpoint that queues up data to be added to Typesense, rather than actually waiting for the embeddings to be generated. To amend my earlier suggestion, Typesense doesn't need to actually add the documents to the index without embeddings initially - just validate them so it can respond success/fail, then throw them in a queue for processing.
additional query latency
I don't have enough documents to test what is typical during an import without text embeddings. But while generating the embeddings, I'm seeing search latency of 2.5s to beyond the timeout of 5s which is problematic for a live site. I have a theory here, but correct me if I'm wrong. Typesense internally queues up index writes in small batches (of around 40 documents?). I guess that's the "Pending Write Batches" on the dashboard of Typesense Cloud. It interleaves these batch writes with incoming reads. Without text embeddings, a write of 40 documents would take an insignificant amount of time, maybe a few milliseconds. So the additional latency to a queued read is minimal. But if each of those 40 documents needs text embeddings and they take at least 250ms each - potentially much more than that with a large model - then that write of 40 or so documents takes much longer, and the read is potentially delayed many seconds. Would I be on the right track? That definitely aligns with the behaviour I'm seeing. It means semantic search is great for a fixed index or one that can be updated offline, but is problematic for an index being accessed live and regularly updated - like my ecommerce website.
k
You're correct about how batching of writes and interleaving works. One option is to create a new collection and index the data in the background and switch to the new index using the alias feature. I agree that it will be useful to have a queue within Typesense so that one can dump all the records to be (re)indexed at one go but let Typesense chew threw them slowly in the background. However, the gotcha with this model is how to communicate indexing failures. We have to keep a record of the index status of each record that's failed to be indexed and expose an API where this is available for clients to use.
If you have enough cpu cores, the parallel indexing on a new collection will not interfere with searches on another collection.
e
Thanks Kishore. That's a good way of handling complete re-indexes. With 2 vCPU I can indeed read another index just fine while generating embeddings on another. I'm still worried about the huge search latencies while inserting/updating even a few records with text embeddings. I experimented with setting
{batch_size: 2}
on the import. I expected that would make the import slower overall, but reduce the search latency because Typesense would service the read queue much more often. I don't get that result though - search latencies are still at least several seconds, with about half hitting the 5s timeout. Are you sure that
batch_size
param is actually working? It seems to have no effect on the latency or on the Pending Write Batches shown on the dashboard. I'd have expected that to spike much higher. I'm no C++ expert but I had a look through the source and can't see it doing anything useful. Thanks for persisting with me!
k
In recent versions the batch size param doesn't have as much of an impact as it did earlier. When I meant by smaller batches, I meant sending smaller documents via the post request. But that's only possible if you can buffer writes in a queue on your end.
e
Yeah that buffering is hard to do on my end. I was hoping to use
batch_size
to get Typesense to check the read queue more often
Semantic search just doesn't seem practical in my situation (regular inserts/updates to the index with auto-generated embeddings and no tolerance for downtime/excess latency). That would be a pretty common scenario for anyone in ecommerce so I'm keen to see what feedback you get from other users as more people try semantic search. Something still feels wrong to me with how Typesense is managing that read queue while generating embeddings. I don't see the same problems when importing to a collection without embeddings. I can't explain the excessively large latency and I wish my C++ knowledge was better!
k
Embedding generation is just an intensive process and doing this often on a two core machine is not going to be feasible if you also have lot of concurrent writes and reads. Even if we manage the read queue we will have to really end up slowing down indexing several times to have acceptable read times. GPU instances will be much more faster, maybe you can try that but that does cost more due to the unit economics.
e
Makes sense. I might have to make my code smarter about rate-limiting the imports it tries to do. Thanks for your help!