Skip to main content

Response time breakdown

A typical LangChat chat() call involves: The two LLM calls dominate. Everything else is fast.

Use a faster model

The single highest-impact change. gpt-4o-mini is ~5× faster and ~20× cheaper than gpt-4o:
For even faster responses at lower quality, try Mistral’s small models or Gemini Flash:

Reduce context size

Smaller prompts = faster LLM calls + lower cost. Reduce history window:
Reduce reranker top_n:
Use smaller chunks:
Smaller chunks mean shorter context per retrieved document.

Use smaller embedding model

Switch to text-embedding-3-small for faster, cheaper embeddings:
You must re-create your Pinecone index (1536 dimensions) and re-index all documents when switching embedding models.

Concurrent users

LangChat’s chat() is async and non-blocking. Run multiple chats concurrently:
For the API server, use multiple uvicorn workers:

Session caching

Sessions are cached in memory. The first call for a user loads history from Supabase; subsequent calls use the in-memory cache. No extra configuration needed. After a server restart, the cache is empty — first calls incur a Supabase query. For large-scale deployments with many unique users, the history loading is fast (Supabase queries are indexed by user_id and platform).

Cost optimization


Background operations

LangChat saves chat history and metrics to Supabase in background threads — these never block the response:
This design means your users get responses as fast as the LLM allows, without waiting for database writes.