01 · AI क्या है?
AI क्या है?
आर्टिफ़िशियल इंटेलिजेंस ऐसा सॉफ़्टवेयर है जो हाथ से लिखे नियमों पर चलने के बजाय उदाहरणों से पैटर्न सीखता है। लाखों ईमेल देख चुका स्पैम फ़िल्टर खुद सीख लेता है कि स्पैम कैसा दिखता है; कोई हर नियम नहीं लिखता।
कोडिंग टूल्स में जो AI होता है, वह एक लार्ज लैंग्वेज मॉडल या LLM है। इसे भारी मात्रा में टेक्स्ट और कोड — किताबें, वेबसाइटें, डॉक्यूमेंटेशन, ओपन-सोर्स रिपॉज़िटरी — पढ़ाकर और अरबों आंतरिक संख्याओं, जिन्हें पैरामीटर कहते हैं, को बार-बार समायोजित करके ट्रेन किया गया, जब तक कि यह एक काम में बहुत अच्छा न हो गया: यह अंदाज़ा लगाना कि आगे कौन सा टेक्स्ट आएगा।
यह छोटा सा काम लगता है, लेकिन किसी प्रोग्राम की अगली लाइन सही अंदाज़ा लगाने के लिए मॉडल को व्याकरण, तथ्य, प्रोग्रामिंग भाषाओं के नियम और समस्याएँ हल करने की व्यावहारिक समझ सीखनी पड़ती है। यह जो कुछ भी करता है — सवालों के जवाब देना, कोड लिखना, बग ठीक करना — सब इसी एक कौशल पर टिका है।
गहराई से समझेंTransformers, layers and parameters · तकनीकी नोट्स, अंग्रेज़ी में
Today's language models are transformers. Text becomes a sequence of token IDs; each ID is looked up in an embedding table to get a vector of a few thousand numbers (the model's width, d_model). That sequence of vectors then flows through a stack of identical blocks — 30 to 120 of them — and each block does two things:
- Self-attention: every position looks back at earlier positions and pulls in the information it needs (which noun does “it” refer to, which variable was declared above).
- A feed-forward network (MLP): a wide two-layer network applied to each position separately, where much of the model's stored knowledge lives.
Residual connections add each block's output back onto its input, and normalisation keeps the numbers in range. At the end, an unembedding matrix turns the final vector into one score (a logit) per vocabulary entry. Parameters are just the entries of all these matrices. For a dense model, a good estimate is:
params ≈ 12 × layers × d_model² (+ vocab × d_model for embeddings)
# e.g. 32 layers, d_model 4096 → 12 × 32 × 4096² ≈ 6.4B (+0.5B embeddings) ≈ "7B"
Nothing in that list is a rule about language. All of the behaviour comes from the values the parameters take during training.
02 · मॉडल जवाब कैसे देता है
मॉडल जवाब कैसे देता है
मॉडल बनाने के दो चरण होते हैं। ट्रेनिंग सबसे महँगा हिस्सा है: हज़ारों चिप्स हफ़्तों तक चलते हैं, जबकि मॉडल अपना डेटा पढ़ता है और उसके पैरामीटर ट्यून होते हैं। इसके बाद मॉडल स्थिर हो जाता है। इन्फ़रेंस वह है जो आपके इस्तेमाल करने पर होता है: आपका टेक्स्ट अंदर जाता है और मॉडल थोड़ा-थोड़ा करके जवाब बनाता है।
हर कदम पर मॉडल अब तक लिखी गई पूरी सामग्री देखता है और हर संभावित अगले टुकड़े को एक संभावना देता है। एक टुकड़ा चुना जाता है, टेक्स्ट में जोड़ा जाता है, और यह तब तक दोहराया जाता है जब तक जवाब पूरा न हो जाए। इसीलिए जवाब स्क्रीन पर शब्द-दर-शब्द आते हैं।
टेम्परेचर नाम की सेटिंग तय करती है कि यह चुनाव कितना साहसी हो। कम टेम्परेचर लगभग हमेशा सबसे संभावित विकल्प चुनता है, जो कोड के लिए अच्छा है। ज़्यादा टेम्परेचर कम संभावित शब्दों को भी आने देता है, जो नए विचारों के लिए अच्छा है।
The best language for a quick script is
गहराई से समझेंLogits, softmax, temperature and sampling · तकनीकी नोट्स, अंग्रेज़ी में
The model outputs a logit zᵢ for every token in its vocabulary. Softmax turns logits into probabilities, and temperature T divides them first:
p(i) = exp(zᵢ / T) / Σⱼ exp(zⱼ / T)
T → 0 : all probability on the top token (greedy decoding)
T = 1 : the model's own distribution
T > 1 : flatter — rare tokens get picked more often
Samplers then trim the tail before picking: top-k keeps the k most likely tokens, top-p (nucleus) keeps the smallest set whose probabilities sum to p, and min-p drops tokens below a fraction of the top token's probability. Repetition and frequency penalties lower the logits of tokens already used. A fixed seed makes sampling repeatable on the same hardware and software.
The generation loop
tokens = tokenize(prompt)
kv = prefill(tokens) # one parallel pass over the whole prompt
while True:
logits = forward(last_token, kv) # one step, reusing the cached keys/values
next = sample(logits, T, top_p)
if next == END: break
tokens.append(next); stream(next)
Prefill is a big parallel matrix multiply and is limited by compute; each decode step is tiny and is limited by how fast weights can be read from memory. That split explains most of what you'll see about speed later in this guide.
03 · टोकन
टोकन क्या हैं?
मॉडल अक्षर या पूरे शब्द नहीं पढ़ते। वे टोकन पढ़ते हैं: टेक्स्ट के टुकड़े, जो अक्सर एक शब्द, शब्द का हिस्सा या कोई चिह्न होते हैं। आम अंग्रेज़ी शब्द एक टोकन होते हैं; दुर्लभ शब्द दो-तीन टुकड़ों में बँट सकते हैं। अंग्रेज़ी में एक टोकन लगभग चार अक्षरों के बराबर होता है; हिन्दी जैसी भाषाओं में उसी बात के लिए अक्सर ज़्यादा टोकन लगते हैं। कोड में चिह्नों और इंडेंटेशन की वजह से हर लाइन में ज़्यादा टोकन लगते हैं।
टोकन इसलिए मायने रखते हैं क्योंकि मॉडल इन्हीं से मापे और बिल किए जाते हैं। कीमतें प्रति दस लाख टोकन बताई जाती हैं — आप जो भेजते हैं (इनपुट) उसकी एक कीमत और मॉडल जो लिखता है (आउटपुट) उसकी दूसरी। आउटपुट आमतौर पर कई गुना महँगा होता है।
गहराई से समझेंByte-pair encoding and vocabularies · तकनीकी नोट्स, अंग्रेज़ी में
Most tokenizers use byte-pair encoding (BPE) or a close relative. Training starts from raw bytes and repeatedly merges the most frequent adjacent pair into a new token, until the vocabulary reaches its target size. Frequent strings (“ the”, “function”, four spaces of indentation) end up as single tokens; rare strings fall back to smaller pieces, and ultimately to individual bytes, so any text can be encoded.
- Vocabulary sizes range from about 32,000 (older Llama, Mistral) to 150,000–260,000 (Qwen, Gemma, GPT-4o-era tokenizers). Bigger vocabularies mean fewer tokens per text but a bigger embedding table.
- Languages are not treated equally. English averages about 4 characters per token; many other languages and scripts need noticeably more tokens for the same meaning, so they cost more and fill the context faster. Newer multilingual tokenizers have narrowed the gap.
- Special tokens mark structure the user never types: start and end of a message, role markers such as
<|im_start|>assistant, tool-call delimiters, image placeholders. - Numbers are tokenized oddly (“1234” might be “12” + “34”), which is one reason models used to struggle with arithmetic; many tokenizers now split digits individually.
04 · कॉन्टेक्स्ट विंडो
कॉन्टेक्स्ट विंडो
कॉन्टेक्स्ट विंडो वह मात्रा है जितना टेक्स्ट मॉडल एक बार में देख सकता है: आपके निर्देश, अब तक की बातचीत, कोडिंग एजेंट द्वारा खोली गई फ़ाइलें और वह जवाब जो वह लिख रहा है। यह मॉडल की कार्यशील याददाश्त है। इसके बाहर की कोई भी चीज़ मॉडल के लिए मौजूद ही नहीं है।
कॉन्टेक्स्ट टोकन में मापा जाता है। दस लाख टोकन की विंडो वाला मॉडल एक साथ लगभग साढ़े सात लाख अंग्रेज़ी शब्द रख सकता है — करीब दस उपन्यास या एक मध्यम आकार का कोडबेस। मॉडल खुद आपकी पुरानी चैट याद नहीं रखता; टूल पुराना टेक्स्ट वापस विंडो में डालकर उसे याददाश्त देते हैं। विंडो भर जाने पर सबसे पुरानी सामग्री हटा दी जाती है या उसका सारांश बना दिया जाता है।
- System prompt
- Files
- Chat
- Logs
- Repo
गहराई से समझेंAttention cost, positions and the KV cache · तकनीकी नोट्स, अंग्रेज़ी में
In attention, every token computes a query, a key and a value. Each query is compared with every earlier key, and the resulting weights mix the values:
Attention(Q, K, V) = softmax(Q·Kᵀ / √d) · V
cost of prefill ∝ n² (every token vs. every earlier token)
memory per token = 2 × layers × kv_heads × head_dim × bytes ← the KV cache
During generation the keys and values of past tokens are kept in the KV cache, so each new token only computes its own. That cache grows linearly with context and is often what limits long contexts — far more than the weights. Designs that shrink it: grouped-query attention (many query heads share a few KV heads), multi-head latent attention (DeepSeek; stores a compressed latent instead of full keys and values), sliding-window layers that only look back a few thousand tokens, and hybrids that mix in linear-attention or state-space layers with constant-size memory.
Positions are encoded with RoPE (rotary embeddings), which rotate queries and keys by an angle that depends on position. Context windows are extended after training by stretching those angles (position interpolation, NTK scaling, YaRN) and fine-tuning briefly on long documents. Advertised and effective context differ: models retrieve facts from the start and end of a long prompt more reliably than from the middle, so put the most important material at the edges.
05 · सिस्टम प्रॉम्प्ट
प्रॉम्प्ट और सिस्टम प्रॉम्प्ट
आप जो कुछ भी टाइप करते हैं वह एक प्रॉम्प्ट है। लेकिन आपका संदेश पहुँचने से पहले ही आपका ऐप मॉडल को अपने छिपे हुए निर्देश भेज चुका होता है: सिस्टम प्रॉम्प्ट। यह तय करता है कि मॉडल कौन है, कौन से टूल इस्तेमाल कर सकता है, किस शैली में लिखे और क्या कभी न करे। कोडिंग एजेंट लंबे सिस्टम प्रॉम्प्ट भेजते हैं, जो बताते हैं कि फ़ाइलें कैसे एडिट करें, टेस्ट कब चलाएँ और अनुमति कब माँगें।
इसीलिए एक ही मॉडल दो अलग टूल्स में बिल्कुल अलग लग सकता है: दिमाग वही, निर्देश अलग। अच्छे प्रॉम्प्ट स्पष्ट होते हैं — बताइए आपको क्या चाहिए, वह संदर्भ दीजिए जो मॉडल अंदाज़ा नहीं लगा सकता, आउटपुट का एक उदाहरण दिखाइए और बताइए कि “पूरा हुआ” का मतलब क्या है।
How do I reverse a list in Python?
गहराई से समझेंChat templates and structured output · तकनीकी नोट्स, अंग्रेज़ी में
A conversation is serialised into one token sequence by the model's chat template. The system prompt is simply the first message, wrapped in role markers:
<|im_start|>system
You are a careful coding assistant. Tools: read_file, run_tests …<|im_end|>
<|im_start|>user
How do I reverse a list in Python?<|im_end|>
<|im_start|>assistant
Models are trained to give the system role more authority than user or tool messages (an instruction hierarchy), but it's still just text in the same window. That's the root of prompt injection: instructions hidden in a web page, file or tool result can try to override the real ones. Agents defend with permissions, sandboxes and by treating tool output as data.
Structured output goes further than asking nicely for JSON. With constrained decoding, the runtime compiles a JSON Schema or grammar into a state machine and masks the logits of any token that would break it, so the output is guaranteed to parse. llama.cpp calls these GBNF grammars; hosted APIs expose them as “structured outputs” or “JSON mode”.
06 · कैश हिट
कैश हिट क्या है?
एक कोडिंग एजेंट मॉडल को बार-बार वही बड़ा टेक्स्ट भेजता है: सिस्टम निर्देश, आपकी प्रोजेक्ट फ़ाइलें और अब तक की बातचीत। हर बार केवल आख़िरी कुछ लाइनें बदलती हैं। हर बार यह सब शुरू से प्रोसेस करना धीमा और महँगा होगा।
प्रॉम्प्ट कैशिंग इसका हल है। प्रोवाइडर आपकी रिक्वेस्ट के शुरुआती हिस्से पर किया गया काम सहेज लेता है। अगली रिक्वेस्ट अगर बिल्कुल उसी टेक्स्ट से शुरू होती है, तो वह काम दोबारा करने के बजाय उसे फिर इस्तेमाल करता है। यही कैश हिट है, और कैश किए गए टोकन भारी छूट पर बिल होते हैं। अगर शुरुआत के पास एक भी अक्षर बदल जाए, तो उसके बाद का सब कुछ कैश मिस है और पूरी कीमत पर बिल होता है।
कैश कम समय तक रहते हैं — अक्सर कुछ मिनट — इसलिए व्यस्त सेशन में सबसे ज़्यादा मदद करते हैं। वही काम, कहीं सस्ता और तेज़; इसीलिए टूल हर रिक्वेस्ट की शुरुआत को एक जैसा रखने की पूरी कोशिश करते हैं।
83% cheaper with caching
गहराई से समझेंHow prefix caching works · तकनीकी नोट्स, अंग्रेज़ी में
What's cached is the KV cache of a prompt prefix — the keys and values computed during prefill. Serving engines split the cache into fixed blocks (vLLM's PagedAttention uses 16-token pages), hash each block together with everything before it, and reuse any block whose hash matches a new request. A change at position k changes the hash of every block after k, which is why one edited character near the start invalidates the rest.
cost = cached_tokens × cache_read_price
+ new_tokens × input_price
+ written_tokens × cache_write_price (some providers)
+ output_tokens × output_price
Some APIs cache automatically; others ask you to mark a breakpoint after the stable part (system prompt, tool definitions, documents). Practical rules: keep the stable material first and byte-identical (no timestamps in the system prompt), append rather than edit conversation history, and keep tool definitions in a fixed order. Entries are evicted after minutes of inactivity, or held longer for a fee. Running locally, llama.cpp and Ollama keep the last prompt's KV cache in memory, which is why a follow-up question starts answering almost instantly.
07 · रीज़निंग टोकन
रीज़निंग टोकन
कुछ मॉडल जवाब देने से पहले सोच सकते हैं। तुरंत जवाब देने के बजाय वे पहले तर्क की एक निजी श्रृंखला लिखते हैं: समस्या को तोड़ना, एक तरीका आज़माना, उसे जाँचना और गलतियाँ सुधारना। उसके बाद ही वे अंतिम जवाब लिखते हैं।
इससे वे कठिन समस्याओं में कहीं बेहतर हो जाते हैं, जैसे पेचीदा बग, गणित और किसी बड़े बदलाव की योजना। दिक्कत यह है कि सोचना भी टोकन से बनता है। रीज़निंग टोकन आउटपुट की तरह बिल होते हैं, भले ही आप उन्हें कभी न देखें। कई टूल आपको रीज़निंग का स्तर कम से ज़्यादा तक चुनने देते हैं।
गहराई से समझेंTest-time compute and reinforcement learning · तकनीकी नोट्स, अंग्रेज़ी में
Reasoning models are trained with reinforcement learning on verifiable tasks: maths with checkable answers, code with unit tests, puzzles with known solutions. The model generates long chains of thought; chains that end in a correct answer are rewarded. Over training, behaviours that help — breaking problems down, checking work, backtracking — become more frequent, and the chains get longer.
This adds a second scaling axis: besides a bigger model, you can spend more test-time compute. Accuracy on hard problems rises roughly with the logarithm of the thinking budget, up to a point. Effort settings (low/medium/high) or explicit budget tokens cap that spend.
- Thinking tokens are output tokens: billed as output and generated at decode speed, so they add latency as well as cost.
- Many APIs return a summary or an encrypted copy of the reasoning instead of the raw chain; agents pass it back on the next turn so the model keeps its train of thought between tool calls (interleaved thinking).
- More thinking isn't always better: simple lookups get slower and occasionally worse when a model over-thinks.
08 · टूल और एजेंट
टूल कॉलिंग और एजेंट
अपने आप में मॉडल केवल टेक्स्ट लिख सकता है। टूल कॉलिंग इसे बदल देती है। ऐप मॉडल को बताता है कि कौन से टूल मौजूद हैं — फ़ाइल पढ़ना, कमांड चलाना, वेब सर्च करना — और जब मॉडल को किसी टूल की ज़रूरत होती है, तो वह सामान्य जवाब के बजाय एक संरचित अनुरोध लिखता है। ऐप उस टूल को सचमुच चलाता है और नतीजा वापस देता है। मॉडल उसे पढ़कर तय करता है कि आगे क्या करना है।
इसे एक लूप में रखिए और आपके पास एक एजेंट है: फ़ेल हो रहा टेस्ट पढ़ो, फ़ाइल खोलो, बदलाव करो, टेस्ट फिर चलाओ, और तब तक दोहराओ जब तक वे पास न हो जाएँ। इस साइट का हर कोडिंग एजेंट मूल रूप से यही लूप है।
गहराई से समझेंTool definitions and the agent loop · तकनीकी नोट्स, अंग्रेज़ी में
A tool is described to the model as a name, a description and a JSON Schema for its arguments. The model replies with a structured call instead of text; the client executes it and sends the result back as a tool message.
{"name": "run_tests",
"description": "Run the project's test suite and return failures",
"input_schema": {"type": "object",
"properties": {"path": {"type": "string"}}, "required": []}}
messages = [system, user]
while True:
reply = model(messages, tools)
if not reply.tool_calls: return reply.text
for call in reply.tool_calls: # may run several in parallel
result = execute(call) # sandbox + permission checks here
messages += [reply, tool_result(call.id, result)]
What separates good agents from bad ones is mostly around this loop: precise tool descriptions, small and composable tools, truncating huge outputs, asking permission for risky actions, and context management — summarising or dropping old tool results so long sessions don't overflow the window. tool_choice can force a specific tool or forbid tools; constrained decoding keeps the arguments valid JSON.
09 · MCP
MCP, मॉडल कॉन्टेक्स्ट प्रोटोकॉल
मॉडल जो भी टूल इस्तेमाल करता है, उसे किसी न किसी को जोड़ना पड़ता है। MCP से पहले हर ऐप हर सर्विस को अपने तरीके से जोड़ता था। मॉडल कॉन्टेक्स्ट प्रोटोकॉल इस जुड़ाव का साझा मानक है — इसे AI टूल्स का USB-C समझिए।
एक MCP सर्वर किसी सर्विस — GitHub, डेटाबेस, ब्राउज़र, आपकी डिज़ाइन फ़ाइलें — को लपेटता है और बताता है कि वह कौन से टूल देता है। MCP समझने वाला कोई भी ऐप उसे जोड़ सकता है और मॉडल तुरंत उन टूल्स का इस्तेमाल कर सकता है। सर्वर एक बार लिखिए और वह हर जगह चलता है — इसीलिए इतने सारे सर्वर इतनी जल्दी आ गए।
गहराई से समझेंInside the protocol · तकनीकी नोट्स, अंग्रेज़ी में
MCP is JSON-RPC 2.0 between a client (inside the agent or IDE) and a server. Local servers run as a subprocess and talk over stdio; remote ones use Streamable HTTP, with OAuth 2.1 for login. The session starts with an initialize handshake in which both sides declare their capabilities.
→ {"jsonrpc":"2.0","id":1,"method":"tools/list"}
← {"jsonrpc":"2.0","id":1,"result":{"tools":[{"name":"create_issue",
"description":"Open a GitHub issue","inputSchema":{…}}]}}
→ {"jsonrpc":"2.0","id":2,"method":"tools/call",
"params":{"name":"create_issue","arguments":{"title":"Fix login"}}}
Servers offer three primitives: tools (actions the model can call), resources (data the app can read into context, addressed by URI) and prompts (reusable templates the user can invoke). Clients can offer sampling (the server asks the host's model to generate text) and elicitation (the server asks the user a question). Every tool's schema is sent to the model, so dozens of servers can eat thousands of tokens of context — one reason agents now load tool definitions lazily.
10 · UTCP
UTCP, यूनिवर्सल टूल कॉलिंग प्रोटोकॉल
MCP मॉडल और सर्विस के बीच एक सर्वर रखता है। यूनिवर्सल टूल कॉलिंग प्रोटोकॉल एक अलग सवाल से शुरू होता है: अगर किसी सर्विस का पहले से API है, तो उसे एक और सर्वर में क्यों लपेटें? UTCP एक खुला मानक है जो एजेंट को टूल सीधे कॉल करने देता है।
हर टूल एक मैनुअल प्रकाशित करता है: एक JSON फ़ाइल जो बताती है कि हर टूल क्या करता है, कौन से इनपुट लेता है और उसे कैसे कॉल करें। एजेंट मैनुअल एक बार पढ़ता है, फिर सर्विस से उसी के प्रोटोकॉल, जैसे HTTP या कमांड लाइन, और उसी के लॉगिन से सीधे बात करता है।
दिक्कत यह है कि काम गायब नहीं होता, बस जगह बदल लेता है। एजेंट के क्लाइंट को हर प्रोटोकॉल समझना पड़ता है और लॉगिन, दोबारा कोशिश और गलतियाँ खुद संभालनी पड़ती हैं, और हर टूल अपनी सुरक्षा के लिए खुद ज़िम्मेदार है। MCP के पास सर्वर और कंपनियों का समर्थन भी कहीं ज़्यादा है।
आपको हमेशा के लिए एक चुनना ज़रूरी नहीं: UTCP में मौजूदा MCP सर्वरों को कॉल करने के लिए एक प्लगइन है।
- The agent sends
- Someone maintains
- Login handled by
{
"manual_version": "1.0.0",
"utcp_version": "1.0.1",
"tools": [{
"name": "get_weather",
"description": "Get current weather for a location",
"inputs": {
"type": "object",
"properties": { "location": { "type": "string" } },
"required": ["location"]
},
"tool_call_template": {
"call_template_type": "http",
"url": "https://api.example.com/weather",
"http_method": "GET"
}
}]
}गहराई से समझेंManuals and call templates · तकनीकी नोट्स, अंग्रेज़ी में
A UTCP manual lists tools, each with JSON Schema inputs and outputs and a tool_call_template saying how to reach it. Templates exist for HTTP, server-sent events, streamable HTTP, the command line, text files and MCP itself. The client substitutes the arguments into the template and calls the service directly, with the service's own authentication (API key, OAuth or basic auth, declared in the template and filled from local variables).
agent ──reads manual once──▶ /utcp (JSON)
agent ──GET /weather?location=Oslo──▶ api.example.com # no proxy in between
The trade-off versus MCP: no extra server process and no extra hop, and existing APIs work as they are; but the client must implement every transport, and features MCP standardises — resources, prompts, sampling, server-initiated notifications — are out of scope.
11 · एम्बेडिंग और RAG
एम्बेडिंग और RAG
कंप्यूटर सीधे अर्थों की तुलना नहीं कर सकते, इसलिए मॉडल टेक्स्ट को संख्याओं की सूचियों में बदलते हैं जिन्हें एम्बेडिंग कहते हैं। हर एम्बेडिंग सैकड़ों आयामों वाले स्पेस में एक बिंदु है, और मिलते-जुलते अर्थ वाले टेक्स्ट पास-पास आते हैं — “लॉगिन बग ठीक करो” “ऑथेंटिकेशन एरर” के पास आता है, भले ही दोनों में कोई शब्द साझा न हो।
इससे अर्थ के आधार पर सर्च संभव होती है: हर दस्तावेज़ को एक बार एम्बेड करें, फिर हर सवाल को एम्बेड करके सबसे नज़दीकी दस्तावेज़ निकालें। रिट्रीवल-ऑगमेंटेड जनरेशन या RAG, मॉडल के जवाब देने से पहले उन दस्तावेज़ों को कॉन्टेक्स्ट विंडो में डाल देता है। इसी तरह मॉडल आपके कोडबेस पर कभी ट्रेन हुए बिना भी उसके बारे में जवाब दे सकता है।
गहराई से समझेंVectors, similarity and retrieval pipelines · तकनीकी नोट्स, अंग्रेज़ी में
An embedding model maps text to a vector, typically 384 to 4,096 dimensions. Similarity is usually cosine similarity:
cos(a, b) = (a · b) / (‖a‖ ‖b‖) # 1 = same direction, 0 = unrelated
Search over millions of vectors uses approximate nearest-neighbour indexes such as HNSW graphs or IVF clusters, in a vector database or a library like FAISS. A production RAG pipeline usually adds:
- Chunking: split documents into passages of a few hundred tokens, ideally along headings or function boundaries, with some overlap.
- Hybrid search: combine vectors with keyword search (BM25), which catches exact names, error codes and identifiers that embeddings blur.
- Reranking: a cross-encoder scores the top 50–100 candidates against the question and keeps the best handful.
- Grounded prompting: put the passages in the context with their sources and ask the model to cite them.
Coding agents often skip vectors entirely and search with grep-style tools in a loop — exact, always up to date, and good enough when the model can iterate.
12 · हैलुसिनेशन
मॉडल हैलुसिनेट क्यों करते हैं
मॉडल का काम संभावित टेक्स्ट बनाना है, सच्चा टेक्स्ट नहीं। आमतौर पर दोनों एक ही होते हैं; जब नहीं होते, तो वह पूरे आत्मविश्वास से गलत बात कह सकता है। इसे हैलुसिनेशन कहते हैं।
कोड में यह एक ऐसे फ़ंक्शन के रूप में दिखता है जो मौजूद ही नहीं, एक ऐसा कॉन्फ़िगरेशन विकल्प जो कभी जोड़ा ही नहीं गया, या एक ऐसा पैकेज नाम जो बिल्कुल सही लगता है। ये कम प्रचलित लाइब्रेरी, हाल के बदलावों और सटीक विवरणों में सबसे आम हैं। बचाव: मॉडल को असली स्रोत दें (डॉक्यूमेंटेशन, फ़ाइलें, सर्च), उसे कोड और टेस्ट चलाने दें, और हर ज़रूरी चीज़ जाँचें।
गहराई से समझेंWhy it happens and how it is measured · तकनीकी नोट्स, अंग्रेज़ी में
Pre-training rewards predicting plausible text, not saying “I don't know”; benchmarks that grade only right or wrong reward guessing over abstaining. So a model that hasn't stored a fact still produces the most fact-shaped continuation. Rare facts — seen a handful of times in training — are the most at risk, which is why niche libraries and recent APIs suffer most.
- Calibration measures whether stated confidence matches accuracy. Some evaluations now score abstentions separately and penalise confident errors.
- Grounding (RAG, search, reading the actual source file) moves the answer from memory to the context, where models are much more reliable.
- Verification loops — run the code, run the tests, type-check, call the real API — catch invented functions immediately.
- Package hallucinations are a security problem: attackers register package names that models tend to invent (“slopsquatting”). Check that a dependency exists and is the one you meant before installing it.
13 · मॉडल कैसे ट्रेन होते हैं
मॉडल कैसे ट्रेन होते हैं
मॉडल चरणों में बनता है। पहले आता है प्री-ट्रेनिंग: यह खरबों टोकन पढ़ता है और अगला टोकन भविष्यवाणी करना सीखता है। इसका ज्ञान यहीं से आता है, और यह अब तक का सबसे महँगा चरण है — लेकिन इसका नतीजा अभी एक मददगार असिस्टेंट नहीं होता।
इसके बाद अच्छी बातचीत के उदाहरणों पर फ़ाइन-ट्यूनिंग इसे निर्देश मानना सिखाती है। अंत में रीइनफ़ोर्समेंट लर्निंग: यह काम करने की कोशिश करता है, इसके जवाबों को अंक मिलते हैं — लोगों, दूसरे मॉडलों या स्वचालित जाँच से, जैसे कि कोड अपने टेस्ट पास करता है या नहीं — और अच्छे जवाबों को इनाम मिलता है। कोडिंग मॉडल इतनी तेज़ी से बेहतर हुए हैं, उसकी एक बड़ी वजह यही आख़िरी चरण है।
Write a function that checks whether a word is a palindrome.
गहराई से समझेंLoss, compute and post-training · तकनीकी नोट्स, अंग्रेज़ी में
Pre-training minimises cross-entropy loss: the negative log-probability the model gave to each actual next token, averaged over trillions of tokens. Gradients from that loss nudge every parameter, batch after batch.
loss = − (1/N) Σ log p(tokenₜ | tokens<ₜ)
training compute ≈ 6 × parameters × training tokens (FLOPs)
# 70B params × 15T tokens ≈ 6.3 × 10²⁴ FLOPs
Scaling laws describe how loss falls predictably with more parameters, data and compute; modern models are trained on far more tokens per parameter than the old “compute-optimal” ratio of about 20, because a smaller model that's been trained longer is cheaper to serve.
Post-training turns the predictor into an assistant: supervised fine-tuning on curated conversations; preference optimisation (RLHF with a reward model, or DPO directly on pairs of better/worse answers); and RL with verifiable rewards for maths, code and agent tasks, run in sandboxes with real tools. Distillation trains a smaller model on a larger one's outputs, which is how many fast “mini” and “flash” models are made.
14 · मिक्सचर ऑफ़ एक्सपर्ट्स
मिक्सचर ऑफ़ एक्सपर्ट्स
एक सामान्य या डेंस मॉडल हर टोकन के लिए अपने सारे पैरामीटर इस्तेमाल करता है। मिक्सचर-ऑफ़-एक्सपर्ट्स (MoE) मॉडल कई छोटे सब-नेटवर्क में बँटा होता है, जिन्हें एक्सपर्ट कहते हैं। हर टोकन के लिए एक छोटा राउटर केवल कुछ एक्सपर्ट चुनता है, बाकी खाली रहते हैं।
नतीजा: मॉडल के पास एक विशाल नेटवर्क का ज्ञान होता है, जबकि हर टोकन की लागत एक छोटे मॉडल जितनी होती है। इसीलिए कुल पैरामीटर और एक्टिव पैरामीटर अलग-अलग बताए जाते हैं। कुल आकार तय करता है कि मॉडल चलाने के लिए कितनी मेमोरी चाहिए; एक्टिव आकार तय करता है कि हर टोकन कितना तेज़ और सस्ता है।
गहराई से समझेंRouters, top-k gating and load balancing · तकनीकी नोट्स, अंग्रेज़ी में
In an MoE layer the feed-forward network is replaced by E experts and a router. For each token the router computes a score per expert, keeps the top k and mixes their outputs by those scores:
g = softmax(W_router · x) # one weight per expert
y = Σ_{i ∈ topk(g)} gᵢ · Expertᵢ(x)
active params ≈ shared (attention, embeddings, shared experts) + k/E × expert params
Modern MoEs use many small experts (128–384) with 4–10 active, often plus one always-on shared expert. Training adds a load-balancing term (or a bias adjustment) so tokens spread evenly; otherwise a few experts take all the work. Serving at scale uses expert parallelism — experts spread over many GPUs, tokens routed between them. At home the useful fact is the asymmetry: memory scales with total parameters, speed with active ones, and the rarely-used experts can sit in system RAM while attention runs on the GPU.
15 · क्वांटाइज़ेशन
क्वांटाइज़ेशन (fp8, fp4)
हर पैरामीटर एक संख्या है, और संख्याओं को ज़्यादा या कम सटीकता से रखा जा सकता है। क्वांटाइज़ेशन उन्हें कम बिट्स में रखता है — जैसे 16 की जगह 8 बिट (fp8) या 4 बिट (fp4)। मॉडल छोटा, चलाने में तेज़ और आमतौर पर सस्ता हो जाता है, बदले में गुणवत्ता में थोड़ी, कभी-कभी महसूस होने वाली, कमी आती है।
इसीलिए एक ही ओपन मॉडल अलग-अलग प्रोवाइडर्स पर अलग कीमत का हो सकता है: वे अलग हार्डवेयर पर अलग सटीकता चला रहे हो सकते हैं।
गहराई से समझेंScales, blocks and quantization formats · तकनीकी नोट्स, अंग्रेज़ी में
Quantization maps each weight to a small integer and stores a scale (and sometimes an offset) per block of weights:
q = round(w / scale) # e.g. a 4-bit integer in [-8, 7]
w ≈ q × scale # what the GPU reconstructs on the fly
bits per weight = bits + (scale bits / block size)
# Q4_K: blocks of 32 inside super-blocks of 256, 6-bit scales → ~4.5 bpw;
# Q4_K_M keeps some tensors at Q6_K → ~4.85 bpw on average
- Post-training quantization methods (GPTQ, AWQ, llama.cpp's importance matrix) use a little calibration text to decide where precision matters most and round to minimise output error, not weight error.
- Hardware formats: FP8 (E4M3) is native on recent NVIDIA, AMD and Intel accelerators; MXFP4 and NVFP4 are 4-bit floats with shared block scales supported by the newest GPUs, so 4-bit can run at full speed instead of being unpacked.
- Quantization-aware training (QAT) simulates low precision during training, so the released 4-bit model loses almost nothing.
- Quality loss is measured with perplexity or, better, the KL divergence between the quantized and full-precision output distributions, plus task benchmarks.
16 · ओपन बनाम क्लोज़्ड वेट्स
ओपन बनाम क्लोज़्ड वेट्स
मॉडल के वेट्स उसके सीखे हुए पैरामीटर हैं — वह फ़ाइल जो खुद मॉडल है। क्लोज़्ड मॉडल इन्हें निजी रखते हैं: आप उन्हें केवल लैब के अपने ऐप या API से इस्तेमाल कर सकते हैं। ओपन-वेट मॉडल इन्हें प्रकाशित करते हैं, ताकि कोई भी उन्हें डाउनलोड कर सके, चला सके, फ़ाइन-ट्यून कर सके या उनकी एक्सेस बेच सके।
कच्ची क्षमता में अक्सर क्लोज़्ड मॉडल आगे रहे हैं। ओपन मॉडल आपको विकल्प देते हैं: कीमत और स्पीड पर होड़ करते कई होस्ट, आपकी अपनी मशीनों पर रहने वाला डेटा, और ऐसा मॉडल जो उसके निर्माता के आगे बढ़ जाने के बाद भी चलता रहे।
- Hy4Tencent · 8 hosts$0.42
- Kimi K3.1 ProMoonshot AI · 40 hosts$2.00
- MiniMax M3.1 FlashMiniMax · 38 hosts$0.075
- DeepSeek V4.1 Flash 1017DeepSeek · 78 hosts$0.15
- Muse Spark OpenMeta · 21 hosts$1.25
- Nemotron 3.5 Super VLNVIDIA · 17 hosts$0.15
- Gemini Omni 1.2 FlashGoogle$1.50
- Gemini Omni 1.1 FlashGoogle$1.50
- GLM 5.3 FlashX LegalZ.ai$0.37
- GPT-6.1 Terra ProOpenAI$1.00
- GPT-6.1 TerraOpenAI$1.00
- Gemini 4 ArgonGoogle$2.00
गहराई से समझेंLicences, formats and fine-tuning · तकनीकी नोट्स, अंग्रेज़ी में
“Open weights” isn't automatically “open source”. Licences range from permissive (Apache 2.0, MIT) to custom ones with usage policies, attribution rules or limits for very large companies. The Open Source Initiative's definition of open-source AI also asks for enough information about the training data to reproduce the model, which few releases provide.
Weights are distributed as safetensors files (a simple, memory-mappable format that can't execute code, unlike old pickle checkpoints) with a config.json describing the architecture and a tokenizer. Community conversions add GGUF (llama.cpp) and MLX (Apple).
Open weights can be fine-tuned. LoRA freezes the model and trains a low-rank update for selected matrices — W' = W + B·A, with A and B thin — so only a fraction of a percent of the parameters train; QLoRA does this on a 4-bit base model, which puts fine-tuning a 30B model within reach of a single 24 GB GPU.
17 · घर पर AI चलाना
घर पर AI चलाना
ओपन-वेट मॉडल आपके अपने कंप्यूटर पर चल सकते हैं। रनटाइम नाम का एक प्रोग्राम — Ollama, LM Studio या llama.cpp — मॉडल के वेट्स को मेमोरी में, बेहतर हो तो आपके ग्राफ़िक्स कार्ड की मेमोरी (VRAM) में, लोड करता है और ठीक वैसे ही टेक्स्ट बनाता है जैसे कोई क्लाउड प्रोवाइडर। कुछ भी आपकी मशीन से बाहर नहीं जाता, प्रति टोकन कोई बिल नहीं, और यह ऑफ़लाइन भी काम करता है।
दो संख्याएँ तय करती हैं कि आप क्या चला सकते हैं। मेमोरी तय करती है कि कौन से मॉडल समाएँगे: लगभग पैरामीटर × प्रति वेट बिट्स ÷ 8, साथ में कॉन्टेक्स्ट के लिए जगह। 8 अरब पैरामीटर वाले मॉडल को 4 बिट पर लगभग 5 GB चाहिए; 70 अरब वाले को 40 GB से ज़्यादा। मेमोरी बैंडविड्थ स्पीड तय करती है, क्योंकि हर नए टोकन के लिए सारे एक्टिव वेट्स फिर से पढ़ने पड़ते हैं — इसीलिए कम एक्टिव पैरामीटर वाले मिक्सचर-ऑफ़-एक्सपर्ट्स मॉडल घर पर इतने लोकप्रिय हैं।
कैलकुलेटर खोलिए: यह आपका हार्डवेयर पहचानता है, बताता है कि कौन से मॉडल चलेंगे और कितनी तेज़ी से, कौन से बदलाव या अपग्रेड मदद करेंगे, और उन्हें सेट अप करने की सटीक कमांड देता है।
देखें आपका कंप्यूटर कौन से मॉडल चला सकता है →
गहराई से समझेंThe memory and speed formulas · तकनीकी नोट्स, अंग्रेज़ी में
memory ≈ params × bpw / 8 + KV cache + ~0.8 GB
KV = 2 × layers × kv_heads × head_dim × 2 bytes × context
tok/s ≈ 0.65 × bandwidth / (active_params × bpw / 8)
RTX 4090 (1008 GB/s), 32B dense @ Q4_K_M (19.4 GB): ≈ 34 tok/s
Apple M4 Max (546 GB/s), 30B-A3B MoE @ Q4 (1.8 GB/token): ≈ 100+ tok/s
Dual-channel DDR5 (~80 GB/s), 8B @ Q4 (4.9 GB): ≈ 10 tok/s
Offloading splits the bytes read per token between fast VRAM and slow system RAM; the slow part dominates. Mixture-of-experts models offload best: keep attention, embeddings and shared experts on the GPU (they're read every token), and put routed experts in RAM (each is read only when chosen). The Run AI at home page applies these formulas to every open model with its real attention shape.
18 · मल्टीमोडल
मल्टीमोडल मॉडल
शुरुआती लैंग्वेज मॉडल केवल टेक्स्ट समझते थे। मल्टीमोडल मॉडल इमेज, PDF, ऑडियो और यहाँ तक कि वीडियो भी लेते हैं। कोडिंग में यह हैरानी की हद तक उपयोगी है: टूटे लेआउट या डिज़ाइन मॉकअप का स्क्रीनशॉट चिपकाइए और मॉडल से उसे बनाने को कहिए, या एजेंट को अपने ऐप का स्क्रीनशॉट लेकर अपना काम जाँचने दीजिए।
अंदर से, इमेज भी टोकन बन जाती है। उसे छोटे-छोटे टुकड़ों में काटा जाता है और हर टुकड़ा लगभग एक टोकन बनता है — इसलिए एक बड़ी इमेज उतना ही कॉन्टेक्स्ट ले सकती है जितना टेक्स्ट का एक पेज।
गहराई से समझेंVision encoders and image tokens · तकनीकी नोट्स, अंग्रेज़ी में
Most multimodal LLMs bolt a vision encoder (a Vision Transformer) onto the language model. The image is resized, cut into patches (often 14×14 or 16×16 pixels), each patch becomes a vector, and a small projector maps those vectors into the language model's embedding space, where they sit in the sequence like word tokens. Many models merge neighbouring patches 2×2 to save tokens:
image tokens ≈ (width / 28) × (height / 28) # 14-px patches, 2×2 merge
1024 × 768 → ~37 × 27 ≈ 1,000 tokens
Providers cap the resolution or tile large images, so counts differ by API. Audio is handled the same way — a speech encoder turns audio frames into embeddings — and video as a sequence of sampled frames. “Natively multimodal” models are pre-trained on mixed text and images from the start rather than having vision added later. Generating images is usually a separate system (diffusion, or autoregressive image tokens).
19 · स्पीड
स्पीड: लेटेंसी और थ्रूपुट
दो संख्याएँ तय करती हैं कि मॉडल कितना तेज़ महसूस होता है। लेटेंसी, यानी पहले टोकन तक का समय, यह है कि कुछ दिखने से पहले आप कितनी देर इंतज़ार करते हैं। थ्रूपुट, यानी प्रति सेकंड टोकन, यह है कि शुरू होने के बाद टेक्स्ट कितनी तेज़ी से आता है। छोटे सवाल के लिए लेटेंसी सबसे ज़्यादा मायने रखती है; बड़ी फ़ाइल लिखने वाले एजेंट के लिए थ्रूपुट।
स्पीड मॉडल के आकार, उसकी व्यस्तता और उसे चलाने वाले के हार्डवेयर और सॉफ़्टवेयर पर निर्भर करती है। रीज़निंग मॉडल दिखने वाला जवाब शुरू होने से पहले सोचने में भी समय लगाते हैं।
गहराई से समझेंThe roofline: compute vs memory bandwidth · तकनीकी नोट्स, अंग्रेज़ी में
A chip is limited either by arithmetic (FLOPs per second) or by how fast it can move data (bytes per second). The ratio of work to data — arithmetic intensity — decides which:
decode, batch 1 : ~2 FLOPs per weight byte read → memory-bound
prefill, 2k tok : ~4,000 FLOPs per weight byte → compute-bound
time to first token ≈ queueing + prefill(prompt) + network
That's why serving providers batch many users together: reading the weights once and applying them to 64 requests makes decode far more efficient, at a small latency cost per user. Speculative decoding exploits the same slack for one user: a cheap draft (a small model, or extra prediction heads) proposes several tokens, the big model verifies them all in one parallel pass and keeps the prefix it agrees with — identical output, often 2–3× faster when drafts are accepted. Specialised chips (Cerebras, Groq, SambaNova) keep weights in on-chip SRAM with enormous bandwidth, which is how they reach thousands of tokens per second.
20 · बेंचमार्क
बेंचमार्क कैसे पढ़ें
बेंचमार्क एक मानक टेस्ट है — हर मॉडल को वही काम दिए जाते हैं ताकि स्कोर की तुलना हो सके। कुछ कठिन परीक्षा जैसे सवालों से ज्ञान और तर्क परखते हैं; कोडिंग बेंचमार्क मॉडल को असली प्रोजेक्ट्स के असली बग देते हैं और जाँचते हैं कि उसका सुधार टेस्ट पास कराता है या नहीं।
इन्हें सावधानी से पढ़ें। हो सकता है मॉडल ने ट्रेनिंग के दौरान सवाल देख लिए हों, जिससे स्कोर बढ़ जाता है; लैब चुनती हैं कि कौन से नतीजे दिखाएँ; और एक तरह के काम में ऊँचा स्कोर दूसरे के बारे में कम बताता है। सबसे अच्छा बेंचमार्क आपका अपना काम है — जो काम आप सच में करते हैं, उस पर कुछ मॉडल आज़माइए।
Real GitHub issues fixed in Python repos.
- Claude Opus 4.783.5%
- Gemini 3.5 Flash79.3%
- Claude Opus 4.678.7%
- GLM 5.278.7%
- DeepSeek V4 Pro 081377.6%
- Qwen3.7 Max77.3%
PhD-level biology, chemistry and physics questions.
- Gemini 4 Argon96.4%
- GPT-6 Astra95.8%
- Claude Sonnet 5.595.6%
- GPT-6.1 Sol95.4%
- Gemini 3.8 Flash95.4%
- Gemini 3.7 Flash94.8%
Expert questions across 100+ subjects.
- GPT-6 Astra54.8%
- Claude Fable 5.146.5%
- Gemini 3.1 Pro Preview46.4%
- Claude Sonnet 5.546.1%
- Gemini 3.8 Flash44.5%
- GPT-5.4 Pro44.3%
Few-shot abstract reasoning on grid puzzles.
- GPT-6 Astra95.0%
- GPT-6.1 Sol94.2%
- Claude Opus 5.593.3%
- GPT-5.6 Sol92.5%
- Gemini 4 Argon91.3%
- Claude Opus 590.4%
गहराई से समझेंContamination, pass@k and arena ratings · तकनीकी नोट्स, अंग्रेज़ी में
- Contamination: if test questions leaked into training data, scores measure memory. Defences include held-out private test sets, fresh problems dated after a model's cutoff (LiveCodeBench-style) and checking whether a model can complete a question it shouldn't know.
- pass@k for code is the probability that at least one of k samples passes the tests, estimated without bias from n ≥ k samples with c correct:
pass@k = 1 − C(n−c, k) / C(n, k). Agentic benchmarks such as SWE-bench Verified give the model a real repository and issue, then run the project's hidden tests on its patch. - Arena ratings come from people comparing two anonymous answers; a Bradley–Terry model turns millions of votes into Elo-like scores. They measure preference — including style and length — not correctness.
- Watch the error bars: on a 500-question test, ±2 points is often noise. And benchmarks saturate — once top models score above 90%, differences stop meaning much and a harder test replaces it.
उदाहरण सार्वजनिक मॉडल और प्रोवाइडर कैटलॉग से गणना किए गए हैं। आवाज़ Magnific से।