<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Karthiknadar on Medium]]></title>
        <description><![CDATA[Stories by Karthiknadar on Medium]]></description>
        <link>https://medium.com/@karthiknadar1204?source=rss-9315f0f6a692------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ba36BKjGTc6ZDc09bZgEmQ.jpeg</url>
            <title>Stories by Karthiknadar on Medium</title>
            <link>https://medium.com/@karthiknadar1204?source=rss-9315f0f6a692------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:16:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@karthiknadar1204/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Claude Think Tool Explained: How It Works in AI Agents]]></title>
            <link>https://pub.towardsai.net/claude-think-tool-explained-how-it-works-in-ai-agents-9e52b2ca12cc?source=rss-9315f0f6a692------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e52b2ca12cc</guid>
            <category><![CDATA[ai-tool-calling]]></category>
            <category><![CDATA[tool-loop]]></category>
            <category><![CDATA[context-engineering]]></category>
            <dc:creator><![CDATA[Karthiknadar]]></dc:creator>
            <pubDate>Fri, 27 Nov 2026 13:01:03 GMT</pubDate>
            <atom:updated>2026-11-27T13:01:03.779Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aeeGzeLm3cuGhSXxauwGYQ.png" /></figure><p>An AI agent can call the right tool and still make the wrong decision afterward. A search might return conflicting information. A database lookup might leave a required field unresolved. A test result might show that the agent’s original explanation for a bug was wrong.</p><p>The next step depends on understanding what just happened. Having access to tools does not automatically make that interpretation reliable.</p><p>Anthropic’s <strong>Claude think tool</strong> explored a simple way to give the model space to work through new information during a task. It used the same tool-calling interface as an ordinary function, but its purpose was to record a working note before the agent continued.</p><p>There is an important update to keep in mind. Anthropic now recommends native extended thinking over a separate think tool in most cases. The original technique is still useful to understand, especially if you are learning how agent loops and scratchpads work. <a href="https://www.anthropic.com/research/claude-think-tool">Anthropic&#39;s updated article</a></p><h3>What is the Claude think tool?</h3><p>The original think tool is a function that accepts a text argument. That text is a note generated by the model. The function does not need to search for information, call another language model, or change an external system.</p><p>In fact, the think handler in the original τ-bench implementation returns an empty string:</p><pre>def think(thought: str) -&gt; str:<br>    return &quot;&quot;</pre><p>The function body is almost empty because the useful content has already appeared in the model’s tool-call arguments. The surrounding application keeps that call in the conversation history. <a href="https://github.com/sierra-research/tau-bench/blob/main/tau_bench/envs/airline/tools/think.py">Original τ-bench implementation</a></p><p>This is the first distinction worth understanding: <strong>the model generates the note; the tool handler does not generate it. </strong>The tool gives that note a defined place in the interaction.</p><h3>Start with an ordinary tool-calling loop</h3><p>Before adding a scratchpad, it helps to understand the loop it becomes part of. When we give Claude a custom tool, we provide a description and an input schema. Claude uses those instructions to decide whether to request the tool and what arguments to supply. Our application then executes the function and returns its result.</p><pre>User request<br>     ↓<br>Claude requests a tool<br>     ↓<br>Application runs the function<br>     ↓<br>Application returns the result<br>     ↓<br>Claude continues</pre><p>The model does not directly execute our Python function. It produces a structured request that our code handles. That distinction is part of Anthropic’s <a href="https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works">tool-use contract</a>. The application supplies the operations, the model requests them, and the results return through the conversation.</p><p>A task can involve several trips through this loop. Each result may change which action makes sense next.</p><h3>Where a scratchpad fits</h3><p>A plan made before the first tool call cannot account for every fact that later calls will reveal. The agent may discover that information is missing, that two sources disagree, or that an earlier assumption no longer holds. It needs to interpret those results before choosing what to do next.</p><p>The think tool adds an explicit place for a working note:</p><pre>Claude requests an information-gathering tool<br>                      ↓<br>Application returns new information<br>                      ↓<br>Claude writes a note through the think tool<br>                      ↓<br>Application acknowledges the call<br>                      ↓<br>Claude continues with the updated conversation</pre><p>The extra step can help separate what the agent has observed from what it still needs to check. For example, an illustrative note might say:</p><pre>The sources describe different versions of the API.<br>The current behavior is still unverified.<br>Check the latest documentation before answering.</pre><p>This is a short task note based on available evidence. It identifies an unresolved issue and a next check. The note does not establish which source is correct. That still requires verification. Its value is that the unresolved issue becomes explicit before the agent continues.</p><h3>How a function that returns nothing can be useful</h3><p>The empty function body can make the technique look strange at first. Usually, we add a tool because its output provides something the model does not already have. A search returns pages. A calculation returns a number. A file-reading function returns text.</p><p>With think, the important content is in the request. Claude generates the note while constructing the tool call. That call then becomes part of the continuing conversation, alongside the earlier tool results.</p><p>The next model request can include:</p><pre>Earlier instructions<br>Earlier observations<br>The think tool call and its note<br>The acknowledgement</pre><p>There is no additional source of intelligence inside the handler. The technique changes the interaction by giving the model an explicit opportunity to produce intermediate working text.</p><p>It also depends on the application preserving that text. Calling a function and discarding the surrounding conversation would remove much of the mechanism we are trying to use.</p><h3>A simple Python implementation</h3><p>There are two parts to define: the interface Claude sees and the function our application runs.</p><p>The following example demonstrates the original custom-tool pattern. For a new Claude application, check native thinking support before deciding to add a separate scratchpad tool.</p><h3>Define the tool interface</h3><pre>THINK_TOOL = {<br>    &quot;name&quot;: &quot;think&quot;,<br>    &quot;description&quot;: (<br>        &quot;Record a brief working note after inspecting tool results. &quot;<br>        &quot;Use it to note confirmed facts, missing information, &quot;<br>        &quot;and the next check. It does not fetch data or perform actions.&quot;<br>    ),<br>    &quot;input_schema&quot;: {<br>        &quot;type&quot;: &quot;object&quot;,<br>        &quot;properties&quot;: {<br>            &quot;thought&quot;: {<br>                &quot;type&quot;: &quot;string&quot;,<br>                &quot;description&quot;: (<br>                    &quot;A short task note based on the available evidence.&quot;<br>                ),<br>            }<br>        },<br>        &quot;required&quot;: [&quot;thought&quot;],<br>    },<br>}</pre><p>The name identifies the tool. The description explains its purpose and when it is useful. The schema specifies the argument the model must provide.</p><p>The Python implementation is not part of this definition. Claude receives the interface, while our application keeps responsibility for execution. Anthropic’s <a href="https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools">tool-definition documentation</a> describes this structure.</p><h3>Implement the handler</h3><pre>def think(thought: str) -&gt; str:<br>    return &quot;Noted.&quot;</pre><p>This handler acknowledges the call. It does not repeat the note because the note is already present in the tool-call arguments.</p><p>An illustrative call could look like this:</p><pre>{<br>  &quot;type&quot;: &quot;tool_use&quot;,<br>  &quot;id&quot;: &quot;toolu_example&quot;,<br>  &quot;name&quot;: &quot;think&quot;,<br>  &quot;input&quot;: {<br>    &quot;thought&quot;: &quot;The sources refer to different API versions. Verify the current documentation before answering.&quot;<br>  }<br>}</pre><p>The application executes:</p><pre>think(<br>    thought=(<br>        &quot;The sources refer to different API versions. &quot;<br>        &quot;Verify the current documentation before answering.&quot;<br>    )<br>)</pre><p>and returns the acknowledgement.</p><p>Writing the note to a separate application log is optional. Keeping it in the model’s continuing conversation is the part that matters for this example.</p><h3>Keep the tool call in the conversation</h3><p>When the API returns a tool request, the next request should preserve the assistant’s content and include the corresponding tool result.</p><p>Here is a small helper for successful client-tool calls:</p><pre>def append_tool_round(messages, response, handlers):<br>    messages.append({<br>        &quot;role&quot;: &quot;assistant&quot;,<br>        &quot;content&quot;: response.content,<br>    })</pre><pre>results = []</pre><pre>for block in response.content:<br>        if block.type != &quot;tool_use&quot;:<br>            continue</pre><pre>output = handlers[block.name](**block.input)</pre><pre>results.append({<br>            &quot;type&quot;: &quot;tool_result&quot;,<br>            &quot;tool_use_id&quot;: block.id,<br>            &quot;content&quot;: output,<br>        })</pre><pre>messages.append({<br>        &quot;role&quot;: &quot;user&quot;,<br>        &quot;content&quot;: results,<br>    })</pre><p>The handlers dictionary connects tool names to their Python functions:</p><pre>handlers = {<br>    &quot;think&quot;: think,<br>}</pre><p>An application with other custom tools would register their handlers here too.</p><p>Two details in the helper are important.</p><ol><li>First, it preserves response.content. That includes the think call and the note Claude supplied.</li><li>Second, each result contains a tool_use_id matching the call it answers. The acknowledgement belongs to that specific invocation.</li></ol><p>Returning only &quot;Noted.&quot; without preserving the assistant&#39;s call would leave out the useful text. Anthropic&#39;s <a href="https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls">tool-result documentation</a> explains the required message structure.</p><h3>Continue the existing agent loop</h3><p>Inside an application that already has a configured client, model, tools, and message history, the continuation follows the usual pattern:</p><pre>while response.stop_reason == &quot;tool_use&quot;:<br>    append_tool_round(messages, response, handlers)<br><br>    response = client.messages.create(<br>        model=MODEL,<br>        max_tokens=2048,<br>        tools=[THINK_TOOL],<br>        messages=messages,<br>    )</pre><p>This example exposes only the think tool. A real agent would include its other tool definitions in the same tools list and register their handlers.</p><p>The loop repeats because Claude may request another tool before finishing. Production code also needs to handle tool failures, iteration limits, and responses that stop because they reach an output limit. The scratchpad uses the same conversation mechanism as the other custom tools.</p><h3>The description influences how the tool gets used</h3><p>Adding a function named think does not tell the model what a useful note should contain. A vague instruction can produce vague notes. It can also encourage unnecessary calls that repeat information without helping the next decision.</p><p>The description should make the intended purpose clear. In this example, the note records what the available evidence establishes and what remains unresolved. A short instruction in the system prompt could reinforce that purpose:</p><pre>When tool results leave an important issue unresolved,<br>use the think tool to record a brief task note. <br>Identify the missing information and the next check.<br>Keep the note concise and grounded in observed results.<br>Skip the tool when the next action is already clear.</pre><p>This is a suggested instruction for the example, rather than a claim that this exact wording has been benchmarked. It asks for a concise task note. It does not ask the model to expose private internal reasoning.</p><p>For current Claude integrations, Anthropic’s tool guidance recommends requesting short explanations or supporting evidence in tool arguments, while keeping internal reasoning in native thinking blocks. <a href="https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools">Current tool-description guidance</a></p><h3>How this relates to context and memory</h3><p>A scratchpad note can influence a later step only if the model receives it. In the implementation above, that happens through messages. The next request includes the earlier conversation, the assistant&#39;s tool call, and the result.</p><p>This makes the note part of the model’s available context. It does not automatically make it permanent memory. If the application starts a new conversation without carrying the note over, that new conversation does not receive it. Similarly, saving a note to a file does not make the model aware of the file’s contents unless the application provides a way to read them.</p><p>The <a href="https://platform.claude.com/docs/en/build-with-claude/context-windows">context-window documentation</a> explains how messages and tool results contribute to what the model can reference. There is also a practical cost to keeping notes. They add generated text, occupy context, and may be included in subsequent requests. Repeated notes that no longer affect the task can become unnecessary input.</p><p>A useful working note should make an unresolved issue easier to track. It should not become another long document the agent has to interpret.</p><h3>What Anthropic’s experiments showed</h3><p>Anthropic evaluated the original technique using Claude 3.7 Sonnet, including experiments on τ-bench. The benchmark places an agent in conversations with simulated users and gives it tools and domain-specific policies. Its evaluation checks whether the interaction reaches the intended outcome.</p><p>It also measures consistency using <strong>pass^k</strong>. This estimates success across all of several independent attempts at a task. It differs from pass@k, which counts a task as successful if at least one attempt succeeds. <a href="https://arxiv.org/abs/2406.12045">τ-bench paper</a></p><p>For the retail domain, Anthropic reported:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aupFeinXbAHMa7LoEUrezQ.png" /></figure><p>These results show an improvement in that experimental setting. The article also reports stronger airline results when the tool was paired with optimized instructions. <a href="https://www.anthropic.com/research/claude-think-tool">Anthropic’s evaluation</a></p><p>The scope matters. These are results for particular models, tasks, and prompts. They do not establish that adding a tool with the same name improves every agent.</p><p>They also give us a reason to evaluate the whole configuration. A tool description, system instructions, and the model’s behavior can all affect what happens after we add the function.</p><h3>Think tool versus native thinking</h3><p>The original article described a distinction between extended thinking before action and a custom tool that could introduce working text during a sequence of actions. Current Claude capabilities make that distinction less useful as a general rule.</p><p>Anthropic now documents <strong>interleaved thinking</strong>, which lets Claude reason between tool calls. The model can consider a tool result before deciding what to do next without needing a separate custom think invocation. Adaptive thinking supports this automatically on models that offer that mode. <a href="https://platform.claude.com/docs/en/build-with-claude/thinking">Current thinking documentation</a></p><p>The two approaches also represent their content differently:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hna9i-WLvC_GD4YW93ZBHQ.png" /></figure><p>A custom tool note is ordinary generated application content. It should not be treated as a direct view into the model’s private reasoning. Native thinking also has model-specific configuration and message-handling requirements. The current documentation is the right place to check those details before copying a setup intended for an older model.</p><p>For most new Claude applications, Anthropic’s updated recommendation makes native thinking the starting point. The custom tool remains a useful example of how intermediate text can become part of an agent’s continuing context.</p><h3>How to decide whether a scratchpad helps your agent</h3><p>Start with a failed run. Find the point where the agent received useful information but did not use it correctly. Perhaps it ignored a conflict, continued with an outdated assumption, or acted before collecting a required detail.</p><p>That gives you something specific to test. A scratchpad step is more relevant to that kind of failure than to a simple lookup whose result can be returned directly. If no intermediate decision needs reconsideration, another tool round may mostly add time and tokens.</p><p>For a meaningful comparison, keep the tasks, model, and available tools fixed. Compare the existing behavior with a clearly defined alternative, such as native thinking or a custom note tool.</p><p>Look beyond whether the agent produced longer notes. Check whether it chose the right next action and reached the intended outcome. Repeated attempts can help reveal whether an apparent improvement is consistent. The code walkthrough above shows how to preserve a note. It does not establish that the note improves a particular application.</p><h3>What to check before adding another tool</h3><p>The useful question is where the agent first stopped using the evidence correctly. If the tool result was incomplete, the agent may need another lookup. If the result contradicted an assumption, it may need to revise its plan. If the next step was already obvious, an extra note may add little.</p><p>That is a more useful starting point than adding a scratchpad to every workflow. It gives you a concrete failure to address and a way to compare the available approaches.</p><p>I write about context, retrieval, and how AI agents work. Follow along if you found this breakdown useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e52b2ca12cc" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/claude-think-tool-explained-how-it-works-in-ai-agents-9e52b2ca12cc">Claude Think Tool Explained: How It Works in AI Agents</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Late Chunking: Giving RAG Embeddings More Context]]></title>
            <link>https://pub.towardsai.net/late-chunking-giving-rag-embeddings-more-context-084b1c5fc934?source=rss-9315f0f6a692------2</link>
            <guid isPermaLink="false">https://medium.com/p/084b1c5fc934</guid>
            <category><![CDATA[chunking]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[late-chunking]]></category>
            <dc:creator><![CDATA[Karthiknadar]]></dc:creator>
            <pubDate>Tue, 24 Nov 2026 17:16:06 GMT</pubDate>
            <atom:updated>2026-11-25T03:47:15.870Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-hjWX7ydUulCh1xvDyCuvw.png" /></figure><p>In a typical RAG pipeline, we split documents into chunks, create an embedding for each chunk, and store the results in a vector database. It is a familiar sequence, and most discussions about improving it start with the chunks themselves. How large should they be? Where should they end? How much should they overlap?</p><p>Those choices matter. But there is another part of the process that deserves attention: what the embedding model gets to see when it creates each chunk’s vector.</p><p>A paragraph can be easy to understand inside a document and much less clear when we read it alone. It might refer to a definition from an earlier section, sit under a heading that establishes its subject, or use “the company” after mentioning the company’s name several paragraphs ago.</p><p>When we embed that paragraph independently, we remove the surrounding text before the model has a chance to use it.Late chunking changes that order. The embedding model processes a longer stretch of text together, and we produce separate chunk vectors afterward.</p><p>The change sounds small. To understand why it can help, we need to look at what happens between sending text to an embedding model and receiving a vector.</p><h3>Where ordinary chunking loses context</h3><p>Consider this passage:</p><pre>Berlin is Germany&#39;s capital.<br>..more text...<br>The city has an extensive public transport network.</pre><p>Reading the document, we understand that “the city” refers to Berlin. The earlier sentence gives us that connection, so the later sentence does not need to repeat the name.</p><p>Now suppose our chunk boundaries separate those sentences:</p><pre>Chunk A:<br>Berlin is Germany&#39;s capital.</pre><pre>Chunk B:<br>The city has an extensive public transport network.</pre><p>With ordinary chunking, we embed them independently:</p><pre>&quot;Berlin is Germany&#39;s capital.&quot;<br>                ↓<br>         Embedding model<br>                ↓<br>             Vector A<br></pre><pre>&quot;The city has an extensive public transport network.&quot;<br>                ↓<br>         Embedding model<br>                ↓<br>             Vector B</pre><p>While creating Vector B, the model receives a statement about an unspecified city. The input does not tell it that the city is Berlin.</p><p>That missing connection becomes relevant when someone searches for:</p><blockquote><em>Public transport in Berlin</em></blockquote><p>Chunk B contains useful information, but its vector was created without the earlier mention of Berlin. The passage may therefore be harder to retrieve than it would have been with that context available.</p><p>Jina’s <a href="https://jina.ai/news/late-chunking-in-long-context-embedding-models/">original late-chunking article</a> demonstrates this problem using references to Berlin across separate passages.</p><p>We can preserve some connections by making chunks larger or repeating text through overlap. But neither choice guarantees that the information needed to interpret a passage will fit inside its boundaries. A definition can appear much earlier in a document, and a heading can apply to several paragraphs. Late chunking gives us another way to handle that dependency.</p><h3>What happens inside an embedding model</h3><p>Throughout this discussion, the model creating the vectors is the <strong>embedding model</strong>. The language model that writes the final answer comes later, after retrieval.We often describe the embedding model’s job like this:</p><pre>Text → vector</pre><p>That is a useful shorthand when we call an API. It hides the intermediate output that makes late chunking possible. For the kind of model used here, the process looks more like this:</p><pre>Text<br>  ↓<br>Tokens<br>  ↓<br>Contextual vector for each token<br>  ↓<br>Pooling<br>  ↓<br>One vector for the input</pre><p>Tokens are the pieces of text the model processes. Depending on the tokenizer, a token might be a word, part of a word, or punctuation. The transformer processes those tokens and produces a vector for each one. Each vector is a list of numbers, and those numbers depend on the surrounding input.</p><p>The representation of “city,” for example, can change depending on which other words appear around it. This is what we mean by a contextual representation. At this stage, we still have many vectors. The model has not yet combined the entire input into one searchable vector.</p><h3>Pooling combines the token vectors</h3><p>Many embedding models use mean pooling to create that final vector. They average the token vectors, coordinate by coordinate.</p><p>Using small, invented vectors:</p><pre>Token vector 1: [2, 4]<br>Token vector 2: [4, 8]<br>Mean vector:   [3, 6]</pre><p>Real embeddings contain many more numbers, but the averaging operation follows the same principle. The <a href="https://www.sbert.net/docs/package_reference/sentence_transformer/modules.html">Sentence Transformers documentation</a> describes pooling as the step that converts token embeddings into a fixed-size sentence embedding.</p><p>It helps to keep the transformer and pooling steps separate in our heads. The transformer builds representations using the text it receives. Pooling decides which of those representations to combine into one vector. Late chunking uses that separation.</p><h3>What late chunking changes</h3><p>With ordinary chunking, we separate the text before the transformer processes it. Each chunk becomes its own input. With late chunking, the transformer processes the longer text together. We then group its output by chunk boundaries and pool each group separately.</p><pre>Longer document<br>       ↓<br>Embedding model&#39;s transformer<br>       ↓<br>Contextual vectors for all tokens<br>       ↓<br>Group token vectors by chunk boundaries<br>       ↓<br>Pool each group separately<br>       ↓<br>One vector per chunk</pre><p>In the Berlin example, the transformer receives the earlier mention of Berlin while processing the later words “the city.” That gives the token representations an opportunity to reflect the connection.</p><p>We then take the representations belonging to the transport passage and combine them into that passage’s vector. The text of the passage can remain exactly the same. What changes is the information available while creating its representation.</p><h3>Why the surrounding context can survive pooling</h3><p>It might seem strange that we can average only one passage’s token vectors and still benefit from text outside that passage. The reason is that the surrounding text has already influenced those vectors.</p><p>We are averaging representations created with the broader input available. We are not averaging the same representations we would have obtained by processing the passage alone.</p><p>That does not mean a chunk vector contains a complete copy of everything elsewhere in the document. It remains a compressed representation. The model may capture some relationships well and miss others. Late chunking gives the model access to useful context before that compression happens.</p><h3>The context can come from either direction</h3><p>The bidirectional encoders discussed in Jina’s work can use both earlier and later text within their input window.</p><p>A definition that appears after a passage can therefore influence its representation too. We are not creating one finished chunk vector and passing it forward to help create the next one. Jina clarifies this in its <a href="https://jina.ai/news/what-late-chunking-really-is-and-what-its-not-part-ii/">follow-up article</a>. The shared context comes from the transformer processing the input together.</p><h3>Seeing the difference in code</h3><p>A small amount of pseudocode makes the ordering easier to see. Assume we already have a tokenized document and a list of chunk spans. Each span contains the start and end positions of a chunk.</p><p>We will use two helper functions:</p><ul><li>encode_tokens returns a contextual vector for each input token.</li><li>mean_pool averages a group of token vectors.</li></ul><p>These names illustrate the process. They are not calls to a particular library.</p><h3>Ordinary chunking</h3><pre>def ordinary_chunking(document_tokens, chunk_spans):<br>    chunk_vectors = []<br><br>    for start, end in chunk_spans:<br>        chunk_tokens = document_tokens[start:end]<br><br>        token_vectors = encode_tokens(chunk_tokens)<br>        chunk_vector = mean_pool(token_vectors)<br><br>        chunk_vectors.append(chunk_vector)<br><br>    return chunk_vectors</pre><p>Each call to encode_tokens receives one chunk. The transformer can use relationships inside that chunk, but it cannot use tokens that we left out.</p><p>Putting several independent chunks into a batch usually preserves that separation. Batching makes processing more efficient; it does not automatically let the inputs share context.</p><h3>Late chunking</h3><pre>def late_chunking(document_tokens, chunk_spans):<br>    token_vectors = encode_tokens(document_tokens)<br><br>    chunk_vectors = []<br><br>    for start, end in chunk_spans:<br>        chunk_token_vectors = token_vectors[start:end]<br>        chunk_vector = mean_pool(chunk_token_vectors)<br><br>        chunk_vectors.append(chunk_vector)<br><br>    return chunk_vectors</pre><p>Here, the transformer processes the longer input first. The loop then selects and pools different spans of its output. A production implementation needs more care than this sketch shows. Character boundaries must map to the right token positions. Special tokens, padding, task instructions, normalization, and any model-specific projection also need handling.</p><p>The <a href="https://github.com/jina-ai/late-chunking">official late-chunking repository</a> contains the implementation and evaluation code behind the method.</p><h3>Choosing boundaries beforehand is still allowed</h3><p>Both examples already know chunk_spans before they call the model.</p><p>That can look surprising given the name “late chunking.” But choosing a boundary and isolating an input are different operations. We can decide beforehand that a paragraph or a 500-token passage should become one retrieval unit. Late chunking simply lets the transformer process the surrounding text before we apply that boundary to its output.</p><p>The boundary tells us which token representations to pool. It does not have to restrict what the transformer sees.</p><h3>Why this is different from one document embedding</h3><p>The phrase “embed the document first” can cause confusion. It can sound as though we create one finished document vector and then cut that vector into smaller embeddings. Late chunking works with the token representations that exist before whole-input pooling.</p><p>Suppose an encoder produces 768-dimensional representations for an input containing 1,000 tokens. Its intermediate output contains 1,000 vectors, each containing 768 numbers.</p><p>If we want five chunks of 200 tokens, we can pool five groups:</p><pre>Tokens   0 through 199 → chunk vector 1<br>Tokens 200 through 399 → chunk vector 2<br>Tokens 400 through 599 → chunk vector 3<br>Tokens 600 through 799 → chunk vector 4<br>Tokens 800 through 999 → chunk vector 5</pre><p>In this illustration, the result is five vectors containing 768 numbers each. We never need to compress all 1,000 tokens into a single document vector first. Doing so would remove the intermediate structure we need to produce the separate chunk representations.</p><p>This also explains a practical requirement. An endpoint that returns only one finished embedding does not expose enough information to implement late chunking yourself. You need the intermediate token representations, or a service that performs the operation internally.</p><p>The published approach uses suitable models with mean pooling. A large context window alone does not make every model or API interchangeable. Jina’s <a href="https://huggingface.co/jinaai/jina-embeddings-v2-base-en">model documentation</a> shows how token outputs, mean pooling, and normalization fit together.</p><h3>Where the vector database fits</h3><p>By the time the vectors reach the database, the late-chunking work has already happened. Your application or embedding service has processed the document, produced the chunk vectors, and associated each vector with its text and metadata.</p><pre>Document<br>   ↓<br>Choose chunk boundaries<br>   ↓<br>Create embeddings with late chunking<br>   ↓<br>Store chunk text, vector, document ID, and metadata<br>   ↓<br>Vector database indexes the records</pre><p>The database can then use its usual vector-search process. Some database products bundle document processing and embedding integrations. Those integrations may handle parts of this sequence for you. Late chunking still needs support in the embedding pipeline. Uploading a document to a vector database does not, by itself, imply that its chunks receive contextual embeddings.</p><p>For the same chunk boundaries and embedding dimensions, ordinary and late chunking can store the same number of vectors. We use the intermediate token vectors to construct the chunk embeddings, but we do not have to retain all of them in the search index.</p><p><a href="https://weaviate.io/blog/late-chunking">Weaviate’s explanation</a> discusses why this makes late chunking compatible with a conventional vector-search setup.</p><h3>What happens when a question arrives?</h3><p>The query path remains familiar:</p><pre>Question<br>   ↓<br>Query embedding<br>   ↓<br>Search stored chunk vectors<br>   ↓<br>Retrieve chunk text<br>   ↓<br>Answering language model</pre><p>The question becomes a query vector, which we compare with the stored chunk vectors. We retrieve the matching text and give that text to the answering model. Late chunking changes how we prepare the document representations. It does not require the answering model to participate in creating them.</p><h3>Enabling late chunking through an API</h3><p>If the embedding service implements late chunking, using it can be much simpler than writing the pooling logic yourself.</p><p>For example, Jina’s documented v3 API accepts a request body like this:</p><pre>{<br>  &quot;model&quot;: &quot;jina-embeddings-v3&quot;,<br>  &quot;task&quot;: &quot;retrieval.passage&quot;,<br>  &quot;late_chunking&quot;: true,<br>  &quot;input&quot;: [<br>    &quot;Berlin is Germany&#39;s capital.&quot;,<br>    &quot;The city has an extensive public transport network.&quot;<br>  ]<br>}</pre><p>The input pieces should belong to the same document or continuous section, in their original order. With late chunking disabled, the service embeds those pieces independently. With it enabled, the service joins them for model processing, then returns an embedding corresponding to each input item.</p><p>We still receive two vectors. Their values change because the transformer processes the text together. <a href="https://jina.ai/news/jina-embeddings-v3-a-frontier-multilingual-embedding-model/">Jina’s v3 API explanation</a> describes this behavior. This is another place where the distinction between choosing chunks and isolating inputs helps. We supplied separate strings, but the service lets them share context during encoding.</p><p>There is a related limitation worth understanding before using the flag. If we send the entire document as one input item, this API design still returns one embedding for that item. It does not automatically invent a collection of 500-token chunks. The parameter is also specific to the service. Adding late_chunking: true to an arbitrary embedding request will not make an unsupported endpoint perform the method.</p><h3>Context limits still apply</h3><p>Late chunking gives each chunk access to a larger input, but that input still has to fit inside the embedding model’s context window.</p><p>For Jina v3, the documented limit is 8,192 tokens across the input pieces combined when late chunking is enabled. Each piece does not receive its own separate allowance while sharing context with the others. <a href="https://jina.ai/news/migration-from-jina-embeddings-v2-to-v3/">Jina’s migration guide</a> explains this distinction.</p><p>Suppose a document contains approximately 5,000 tokens and we want retrieval chunks of approximately 500 tokens. We can send roughly ten consecutive pieces together and receive ten vectors. The model processes the approximately 5,000-token input together, while each output vector focuses on its own passage.</p><p>This gives us two sizes to choose:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LjIFknbSYT0o5cyVoEX-Ww.png" /></figure><p>Ordinary chunking often makes those sizes nearly identical. Late chunking lets us use a larger input for context while keeping the searchable passages small.</p><h3>Documents longer than the context window</h3><p>A 100,000-token document cannot fit into an 8,192-token encoder input. We therefore need larger sections that fit within the model’s limit, with smaller retrieval chunks inside them. An application might process approximately 6,000 tokens together and create approximately 500-token chunk vectors from that output.</p><p>The paper calls this <strong>long late chunking</strong>. It also uses overlap between the larger windows to provide neighboring context near their boundaries. <a href="https://arxiv.org/pdf/2409.04701">Research paper, Section 3.1</a></p><p>The scope of that context matters. A chunk benefits from the window in which it was encoded. It does not automatically receive information from the rest of the 100,000-token document. If a definition and the passage that depends on it fall into distant windows, late chunking alone does not reconnect them.</p><h3>How it relates to other retrieval techniques</h3><p>It is easy to put every attempt at preserving document context into the same category. In practice, these techniques change different parts of the pipeline.</p><h3>1. Overlapping chunks</h3><p>Overlap repeats some surrounding text inside independently encoded chunks. This often helps near a boundary. A passage gets to include the end of the previous chunk or the beginning of the next one.</p><p>Its reach depends on how much text we repeat, though. A definition several pages earlier can still sit outside the input. Late chunking uses a larger shared input during encoding. Overlap can still be useful when we divide very long documents into encoding windows, or when we assemble readable evidence after retrieval.</p><h3>2. Semantic chunking</h3><p>Semantic chunking tries to find sensible places to divide the document, often by grouping related sentences. That can produce more coherent passages. But a coherent paragraph may still depend on information elsewhere. A clean boundary does not make every paragraph self-contained.</p><p>Late chunking changes the context available when we represent those passages. Jina’s <a href="https://jina.ai/news/what-late-chunking-really-is-and-what-its-not-part-ii/">follow-up article</a> separates boundary selection from context loss. We can choose readable boundaries and use late chunking together.</p><p>We should still care about the text a person or answering model will receive. A contextual vector does not repair a sentence that ends halfway through its explanation.</p><h3>3. Late interaction</h3><p>Late interaction, such as ColBERT, keeps multiple token representations and compares query and document representations through a fine-grained interaction step during retrieval. Late chunking combines token representations into one vector per chunk before retrieval.</p><p>That difference affects both the index and the matching process. The similar names do not mean the two methods preserve the same information or score relevance in the same way. The <a href="https://arxiv.org/abs/2004.12832">ColBERT paper</a> explains its retrieval architecture.</p><h3>4. Contextual Retrieval</h3><p>Anthropic’s Contextual Retrieval takes another route. It generates a short explanation that places each chunk within its document, then adds that explanation to the chunk before indexing it. The enriched text feeds both embeddings and a BM25 keyword index.</p><p>This gives the indexed passage explicit context in words. Late chunking uses the surrounding input to influence the token representations without generating an explanatory prefix.</p><p>Both approaches address missing context, but the changes they make are different. <a href="https://www.anthropic.com/research/contextual-retrieval">Anthropic’s article</a> describes the text-enrichment process and its evaluation.</p><h3>Better retrieval still needs readable evidence</h3><p>There is one more distinction that matters once we connect retrieval to answer generation. A chunk vector can benefit from information that the stored chunk text does not explicitly contain.</p><p>Our transport passage may become easier to retrieve for a Berlin query because the embedding model saw the earlier mention of Berlin. But the text we retrieve still says:</p><pre>The city has an extensive public transport network.</pre><p>The answering model normally receives that sentence. It does not receive the embedding model’s intermediate token representations.</p><p>If it needs to know which city the passage describes, we may need to attach the document title, retrieve a neighboring paragraph, or expand the result to a larger parent section.</p><p>There are two separate checks here:</p><ul><li>Did search find the relevant passage?</li><li>Does the returned text contain enough information to support an answer?</li></ul><p>Late chunking can improve the first while leaving the second unresolved. This is why evaluating the final RAG output still matters. A better retrieval ranking is useful, but we also need to inspect what evidence reaches the answering model.</p><h3>When it is worth testing</h3><p>Late chunking is worth considering when passages repeatedly depend on information outside their boundaries.</p><p>Research papers, manuals, reports, and internal documentation often have that structure. They define terms once and reuse them. Headings establish the subject for several paragraphs. Names appear early, followed by indirect references.</p><p>A short FAQ entry that repeats its subject may already contain most of the context it needs. Processing a larger surrounding section might add much less.</p><p>The easiest place to start is with retrieval failures you already have. Find questions where the correct passage exists but ranks poorly. Read that passage alone, then read it inside its surrounding section. Pay attention to what changes. Perhaps a heading identifies the product, an earlier sentence defines an acronym, or another paragraph explains what “this approach” refers to.</p><p>Those are concrete dependencies that contextual chunk embeddings may help preserve. For the comparison to tell us something useful, keep the embedding model, chunk boundaries, retrieval settings, and evaluation questions fixed. Then change how the chunk representations are created. If we also replace the model or change the chunk size, it becomes harder to tell which change caused the improvement.</p><p>Indexing cost needs its own measurement. Storing the same number of vectors does not establish that processing longer encoder inputs has the same latency or memory requirements as processing separate short chunks.</p><p>Finally, inspect the evidence delivered after retrieval. Check whether the relevant passage appears, whether its subject is clear, and whether the answering model has enough surrounding text to use it correctly.</p><p>That gives us a practical way to judge the method on our own documents: useful passages should become easier to find, the processing cost should remain acceptable, and the returned evidence should support the answer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=084b1c5fc934" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/late-chunking-giving-rag-embeddings-more-context-084b1c5fc934">Late Chunking: Giving RAG Embeddings More Context</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Context Goes Wrong in AI Agents]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://pub.towardsai.net/how-context-goes-wrong-in-ai-agents-45ec0fd381ca?source=rss-9315f0f6a692------2"><img src="https://cdn-images-1.medium.com/max/1672/1*126KRABUaptE2cDpGxUuwg.png" width="1672"></a></p><p class="medium-feed-snippet">An agent&#x2019;s context usually starts out fairly tidy. There&#x2019;s a task, some instructions, and a set of tools. Then the agent gets to work. It&#x2026;</p><p class="medium-feed-link"><a href="https://pub.towardsai.net/how-context-goes-wrong-in-ai-agents-45ec0fd381ca?source=rss-9315f0f6a692------2">Continue reading on Towards AI »</a></p></div>]]></description>
            <link>https://pub.towardsai.net/how-context-goes-wrong-in-ai-agents-45ec0fd381ca?source=rss-9315f0f6a692------2</link>
            <guid isPermaLink="false">https://medium.com/p/45ec0fd381ca</guid>
            <category><![CDATA[context-engineering]]></category>
            <category><![CDATA[ai-memory]]></category>
            <dc:creator><![CDATA[Karthiknadar]]></dc:creator>
            <pubDate>Tue, 24 Nov 2026 00:01:03 GMT</pubDate>
            <atom:updated>2026-11-24T00:01:03.557Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Memory Compaction: How AI Agents Keep the Thread]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@karthiknadar1204/memory-compaction-how-ai-agents-keep-the-thread-89783800da61?source=rss-9315f0f6a692------2"><img src="https://cdn-images-1.medium.com/max/1774/1*n9Wonu6N3XjhvgkS0QAzwQ.png" width="1774"></a></p><p class="medium-feed-snippet">Some conversations are easy to return to. You mention a project, a person, or a plan, and the other person already knows enough to follow&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@karthiknadar1204/memory-compaction-how-ai-agents-keep-the-thread-89783800da61?source=rss-9315f0f6a692------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@karthiknadar1204/memory-compaction-how-ai-agents-keep-the-thread-89783800da61?source=rss-9315f0f6a692------2</link>
            <guid isPermaLink="false">https://medium.com/p/89783800da61</guid>
            <category><![CDATA[context-engineering]]></category>
            <category><![CDATA[ai-memory]]></category>
            <category><![CDATA[compaction]]></category>
            <dc:creator><![CDATA[Karthiknadar]]></dc:creator>
            <pubDate>Sun, 22 Nov 2026 15:46:25 GMT</pubDate>
            <atom:updated>2026-11-22T15:46:25.145Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How NEMORI Helps AI Agents Remember What Matters.]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://pub.towardsai.net/how-nemori-helps-ai-agents-remember-what-matters-0d0a2d6588b6?source=rss-9315f0f6a692------2"><img src="https://cdn-images-1.medium.com/max/1774/1*avq0clyESNLmAxjOpYo_0Q.png" width="1774"></a></p><p class="medium-feed-snippet">You&#x2019;re catching up with a friend you haven&#x2019;t seen in a few weeks. The conversation wanders through the usual things. Work has been busy&#x2026;</p><p class="medium-feed-link"><a href="https://pub.towardsai.net/how-nemori-helps-ai-agents-remember-what-matters-0d0a2d6588b6?source=rss-9315f0f6a692------2">Continue reading on Towards AI »</a></p></div>]]></description>
            <link>https://pub.towardsai.net/how-nemori-helps-ai-agents-remember-what-matters-0d0a2d6588b6?source=rss-9315f0f6a692------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d0a2d6588b6</guid>
            <category><![CDATA[ai-memory]]></category>
            <category><![CDATA[context-engineering]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Karthiknadar]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 23:01:02 GMT</pubDate>
            <atom:updated>2026-10-22T23:01:02.228Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Normal Memory: Because Forgetting Is a Feature for Humans.]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@karthiknadar1204/normal-memory-because-forgetting-is-a-feature-for-humans-40733f9f0ffc?source=rss-9315f0f6a692------2"><img src="https://cdn-images-1.medium.com/max/1280/0*PN3xqLW0dF57oZlH.jpeg" width="1280"></a></p><p class="medium-feed-snippet">Well, let&#x2019;s discuss the origin of normal-memory going into the bushes. I was in on a call with a bunch of builder friends a couple of&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@karthiknadar1204/normal-memory-because-forgetting-is-a-feature-for-humans-40733f9f0ffc?source=rss-9315f0f6a692------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@karthiknadar1204/normal-memory-because-forgetting-is-a-feature-for-humans-40733f9f0ffc?source=rss-9315f0f6a692------2</link>
            <guid isPermaLink="false">https://medium.com/p/40733f9f0ffc</guid>
            <category><![CDATA[ai-memory]]></category>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[context-engineering]]></category>
            <category><![CDATA[self-improving-agent]]></category>
            <category><![CDATA[harness-engineering]]></category>
            <dc:creator><![CDATA[Karthiknadar]]></dc:creator>
            <pubDate>Tue, 13 Oct 2026 06:00:42 GMT</pubDate>
            <atom:updated>2026-10-13T06:00:42.289Z</atom:updated>
        </item>
    </channel>
</rss>