<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Goran Cvijanovic</title>
    <description>The latest articles on DEV Community by Goran Cvijanovic (@gorancv).</description>
    <link>https://dev.to/gorancv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4257896%2F410dcc72-5d1d-4a60-827f-ede8f7796fe4.jpg</url>
      <title>DEV Community: Goran Cvijanovic</title>
      <link>https://dev.to/gorancv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gorancv"/>
    <language>en</language>
    <item>
      <title>Your agent doesn't need the whole document: cutting search-result tokens by 91–96%</title>
      <dc:creator>Goran Cvijanovic</dc:creator>
      <pubDate>Fri, 20 Nov 2026 23:00:00 +0000</pubDate>
      <link>https://dev.to/gorancv/your-agent-doesnt-need-the-whole-document-cutting-search-result-tokens-by-91-96-gjh</link>
      <guid>https://dev.to/gorancv/your-agent-doesnt-need-the-whole-document-cutting-search-result-tokens-by-91-96-gjh</guid>
      <description>&lt;p&gt;Give an agent a search tool and watch what it reads. It asks for articles about energy, gets 20 hits, and every hit carries the full unit: body text, metadata, every field the index holds. The agent needs a key, a type and a heading to decide what to open next. It pays for everything else anyway.&lt;/p&gt;

&lt;p&gt;That is a context-engineering problem hiding in the tool layer. The fix is old and boring: &lt;strong&gt;return only the fields the caller asked for&lt;/strong&gt;. What changed is who the caller is. A human UI ignores the extra fields for free. An LLM pays tokens for every byte, and the noise competes with the part that matters.&lt;/p&gt;

&lt;p&gt;I build &lt;a href="https://github.com/cameodb/cameodb" rel="noopener noreferrer"&gt;CameoDB&lt;/a&gt;, a search database with a native MCP server, so I measured how much this actually saves on a real index.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers
&lt;/h2&gt;

&lt;p&gt;The index is an official gazette published in Italian, 1995–2026: about 905,000 documents, one per act, article or budget-table row, each with typed metadata (act key and type, dates, year, amounts). Each query ran twice on the same node, once returning whole documents and once with a field list. Tokens are estimated at ~4 bytes per token.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Query&lt;/th&gt;
&lt;th&gt;Hits&lt;/th&gt;
&lt;th&gt;Whole documents&lt;/th&gt;
&lt;th&gt;Only the fields needed&lt;/th&gt;
&lt;th&gt;Smaller&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Personal-data rules since 2018 (phrase + numeric range + exact type)&lt;/td&gt;
&lt;td&gt;10 of 109&lt;/td&gt;
&lt;td&gt;20,002 B (~5,000 tokens)&lt;/td&gt;
&lt;td&gt;1,142 B (~285 tokens)&lt;/td&gt;
&lt;td&gt;94.3%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Energy articles 2015–2026 (full-text + numeric range + exact type)&lt;/td&gt;
&lt;td&gt;20 of 119&lt;/td&gt;
&lt;td&gt;51,763 B (~12,940 tokens)&lt;/td&gt;
&lt;td&gt;2,277 B (~569 tokens)&lt;/td&gt;
&lt;td&gt;95.6%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tourist-tax provisions (phrase)&lt;/td&gt;
&lt;td&gt;20 of 34&lt;/td&gt;
&lt;td&gt;32,833 B (~8,208 tokens)&lt;/td&gt;
&lt;td&gt;2,291 B (~572 tokens)&lt;/td&gt;
&lt;td&gt;93.0%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Energy budget lines since 2024 (full-text + numeric comparison)&lt;/td&gt;
&lt;td&gt;20 of 434&lt;/td&gt;
&lt;td&gt;25,236 B (~6,309 tokens)&lt;/td&gt;
&lt;td&gt;2,168 B (~542 tokens)&lt;/td&gt;
&lt;td&gt;91.4%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;91–96% fewer tokens per search call, and each projected query took about a millisecond in the engine. On an agent loop that searches five or ten times per task, that is the difference between a focused context and one that is mostly legal boilerplate.&lt;/p&gt;

&lt;p&gt;To be fair about it: the saving depends on your documents. Long text bodies and wide table rows with short metadata, as here, are the best case. Narrow records save less. The point is to measure your own index, not to trust my percentage.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the query looks like
&lt;/h2&gt;

&lt;p&gt;The second row, over HTTP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s -X POST http://localhost:9480/api/official_gazette/search \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{
    "query": "text:energia AND unit_type:article AND year:[2015 TO 2026]",
    "limit": 20,
    "fields": ["act_key", "act_type", "heading"]
  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;text:energia&lt;/code&gt; is a full-text match, &lt;code&gt;unit_type:article&lt;/code&gt; an exact value and &lt;code&gt;year:[2015 TO 2026]&lt;/code&gt; a numeric range, all in one query. &lt;code&gt;fields&lt;/code&gt; is the projection: the act to open, its type and the article heading. You can also put it inline at the end of the query (&lt;code&gt;... return act_key,act_type,heading&lt;/code&gt;), and the payload wins if both are present. Metadata keys like &lt;code&gt;_score&lt;/code&gt; and &lt;code&gt;_id&lt;/code&gt; always come back.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the projection happens matters
&lt;/h2&gt;

&lt;p&gt;Most search engines can filter the returned source somehow, so the idea itself isn't new. Where it runs is the part worth checking in whatever you use. In CameoDB the projection runs inside the engine, on the shard that holds the document. Only the requested fields are serialized, and a peer never ships the coordinator fields it would throw away.&lt;/p&gt;

&lt;p&gt;The same reasoning applies to big arrays. One field of a threat-intel record can hold hundreds of thousands of IP addresses, so each array in a hit is capped (1,000 elements by default). The hit reports what was cut in &lt;code&gt;_truncated_arrays&lt;/code&gt;, and the elements that matched your query come first, with their stored positions in &lt;code&gt;_matched_elements&lt;/code&gt;. The evidence for a hit stays in the hit, without megabytes of addresses around it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Letting the agent do it over MCP
&lt;/h2&gt;

&lt;p&gt;A projection only helps if the agent knows which fields exist. CameoDB serves MCP on the same port as the REST API, with read-only tools: &lt;code&gt;list_indexes&lt;/code&gt;, &lt;code&gt;describe_index&lt;/code&gt;, &lt;code&gt;validate_query&lt;/code&gt;, &lt;code&gt;search_index&lt;/code&gt;, &lt;code&gt;search_across_indexes&lt;/code&gt; and &lt;code&gt;get_catalog_stats&lt;/code&gt;. &lt;code&gt;describe_index&lt;/code&gt; gives the agent each field's type, whether it is searchable, sortable and returned, and which operators work on it. &lt;code&gt;search_index&lt;/code&gt; takes the &lt;code&gt;fields&lt;/code&gt; list. The agent learns the schema once, then asks for only what it needs.&lt;/p&gt;

&lt;p&gt;Connect Claude Code to a local node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp add --transport http cameodb http://localhost:9480/mcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Setup for Claude Desktop, Cursor, Copilot and the MCP Inspector is in the &lt;a href="https://github.com/cameodb/cameodb/blob/main/crates/mcp/README.md" rel="noopener noreferrer"&gt;MCP client guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One schema habit pays off here: write a &lt;code&gt;description&lt;/code&gt; on the index and on each field. Names and types describe the shape of the data. Only the description says what it &lt;em&gt;is&lt;/em&gt;, and the agent reads it when it picks fields.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;CameoDB is a single Rust binary: a key-value store, a document model and full-text search behind one write path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p &lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;/data/cameodb &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; chown -R 65532:65532 &lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;/data/cameodb
docker run -d --name cameodb-server -p 9480:9480 -p 9580:9580 \
  -v &lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;/data/cameodb:/data/cameodb cameodb/cameodb:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Binaries are on &lt;a href="https://cameodb.com/downloads.html" rel="noopener noreferrer"&gt;cameodb.com/downloads&lt;/a&gt;, and the code is on &lt;a href="https://github.com/cameodb/cameodb" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Load an index you already have, run one query with and without &lt;code&gt;fields&lt;/code&gt;, and compare the response sizes. I'd like to see what the ratio looks like on data that isn't legal text, so post yours in the comments: it shows where this matters and where it doesn't.&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>aiagents</category>
      <category>llm</category>
      <category>search</category>
    </item>
  </channel>
</rss>
