Hi guys, i am using TS official client lib <https:...
# community-help
n
Hi guys, i am using TS official client lib https://github.com/typesense/typesense-js and after seeing few timeout errors in my client (in browser) like this
undefined: Request failed with HTTP code 400 | Server said: API timeout.
i changed configuration of browser-based-typesense-client :
Copy code
const TS_CONNECTION_OPTS_DEFAULT = {
    ...
    'sendApiKeyAsQueryParam': false,
    'numRetries': 5,
    'retryIntervalSeconds': 2,
    'connectionTimeoutSeconds': 20,
    'timeoutSeconds': 20,
    'cacheSearchResultsForSeconds': 5 * 60,
    'useServerSideSearchCache': true, // this send "use_cache: true",  https://typesense.org/docs/30.1/api/search.html#caching-parameters
    'healthcheckIntervalSeconds': 10,
    ...
1. How bad is this? (in my case: new documents added/updated to server every 12 hours, so I could, probably cache even more, what are the correct settings for this?) 2. It would be great to have some chapter in documentation describing: - timeouts settings - client cache vs server cache, how to tune/optimize it - client retry settings - what to do in case of bad/unreliable internet connections thanks in advance!
f
Hey @new_in_town , The main thing to watch out for is this: with a 20s timeout and 5 retries, a single search can take a very long time to finally fail if the connection is bad. That’s usually worse for UX than failing faster and letting the user retry or continue typing. - sendApiKeyAsQueryParam: false is fine. - useServerSideSearchCache: true is also fine, especially if your data only changes every 12 hours. - cacheSearchResultsForSeconds: 5 * 60 is not unreasonable for your use case, as long as you’re okay with users sometimes seeing results that are up to 5 minutes old. - healthcheckIntervalSeconds: 10 is okay, but not something I’d optimize heavily unless you have multiple nodes and actual failover behavior to tune. If this is interactive search in the browser, I’d usually suggest shorter timeouts and fewer retries. Since your documents only change every 12 hours, you can probably cache more aggressively, but the real question is how fresh results need to feel to users. If a few minutes of staleness is acceptable, 5 minutes is perfectly fine. If freshness matters more, reduce it.
n
Great! Great! Important info!👍 Probably I would increase
cacheSearchResultsForSeconds
- 30 min, 1 hour... I want to reduce server load, and server documents get updated every 12 hours ANYWAY. > If this is interactive search in the browser, No, this is NOT "search as you type", this is "select 3-6 criteria, type something, press search button" Another thing is WHY timeout happens. The error is:
undefined: Request failed with HTTP code 400 | Server said: API timeout.
so this look like timeoud INSIDE server process - it responds with HTTP 400. In the past there was no such problems, no timeouts, everything was extremely fast. Some time ago I did this on the server side:
Copy code
{
      "name": "embedding",
      "type": "float[]",
      "num_dim" : 4096,
      "embed": {
        "from": [
          "title",
          "content",
          "tags1",
          "tags2",
          "organization",
        ],
        "model_config": {
          "query_prefix": "query:Given a search query, retrieve relevant passages that answer the query",
          "model_name": "openai/Qwen/Qwen3-Embedding-8B",
          "api_key": ...
          "url": "https://api.studio.nebius.ai/v1/embeddings"
        }
      }
    }
... as far as I understand - every time I do hybrid search my typesense-server talks to api.studio.nebius.ai/v1/embeddings and... all this might cause these timeouts (they happens during HYBRID search). 1. How to diagnose this on the server side? 2. Any server-side settings to tweak ? UPDATE: on the server side I did (in
/etc/typesense/typesense-server.ini
):
Copy code
log-dir = /var/log/typesense
enable-search-logging = true
enable-access-logging = true
log-slow-requests-time-ms = 2000
now where do I find these slow requests, which log file?
Trying things like
grep event=  /var/log/typesense/typesense.log
but now I can not reproduce these slow requests...
f
If you can find the log file, the slow requests will be logged as an info
n
OK, found records with
event=slow_request, time=3175 ms
, good... how to dig deeper? How do I know - is it related to external embedder?
f
Can you share some of those requests?
n
see DM