The psychology of waiting. Streaming vs Bulk.
User A waits 5 seconds for a full paragraph. User B waits 0.5 seconds for the first word, then watches the rest appear.
User A thinks the system is broken. User B thinks it is fast. TTFT (Time To First Token) is the most important metric for User Experience.
In LangChain, never use .invoke() for a chatbot.
Use .stream().
It yields tokens as they are generated.
for chunk in chain.stream("Why represents the sky?"):
print(chunk, end="", flush=True)
# The user sees progress instantly.
Latency = Prefill Time + Generation Time.
If you shove 100 documents into the context "just in case," your Prefill Time explodes. Pruning retrieval (Contextual Compression) saves latency.
If two users ask "What is the capital of France?", why compute it twice?
Semantic Caching stores (Question_Embedding -> Answer).
If a new question is 99% similar to a cached question, return the cached answer instantly (0ms latency).
Latency is physics (Model Size) + engineering (Streaming/Caching). You cannot change physics. You must master engineering.
Key Intuition: "Don't make them wait. Make them watch."