<?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: erdeveshkumardev</title>
    <description>The latest articles on DEV Community by erdeveshkumardev (@erdeveshkumardev).</description>
    <link>https://dev.to/erdeveshkumardev</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%2F4235120%2Fc7d12981-d3ac-46d9-a0f1-0ac9ff42260f.png</url>
      <title>DEV Community: erdeveshkumardev</title>
      <link>https://dev.to/erdeveshkumardev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/erdeveshkumardev"/>
    <language>en</language>
    <item>
      <title>How I Dropped OpenAI Response Latency From 1,800ms to 14ms Using Semantic Caching</title>
      <dc:creator>erdeveshkumardev</dc:creator>
      <pubDate>Mon, 09 Nov 2026 12:18:43 +0000</pubDate>
      <link>https://dev.to/erdeveshkumardev/how-i-dropped-openai-response-latency-from-1800ms-to-14ms-using-semantic-caching-21f6</link>
      <guid>https://dev.to/erdeveshkumardev/how-i-dropped-openai-response-latency-from-1800ms-to-14ms-using-semantic-caching-21f6</guid>
      <description>&lt;p&gt;If you run an AI chatbot, customer support bot, or search feature in production, you've probably noticed that &lt;strong&gt;30% to 60% of user queries are repetitive&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;"What is your refund policy?"&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;"How can I get my money back?"&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;"Return terms please"&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Traditional string hashing (like standard Redis keys) fails because users phrase sentences differently. As a result, you pay OpenAI full token fees and your users wait 2 to 3 seconds for answers that the LLM has already generated dozens of times.&lt;/p&gt;

&lt;p&gt;To solve this, I built &lt;strong&gt;HyperCache-LLM&lt;/strong&gt; — a lightweight, drop-in semantic caching proxy.&lt;/p&gt;

&lt;h3&gt;
  
  
  🏛️ How It Works Under the Hood:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Local ONNX Embeddings&lt;/strong&gt;: It uses a local ONNX model (&lt;code&gt;bge-small-en-v1.5&lt;/code&gt;, 384 dimensions) running directly on CPU in &amp;lt;10ms (Zero external API costs).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In-Memory Cosine Similarity&lt;/strong&gt;: An in-memory matrix checks cosine similarity against cached query vectors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smart Interception&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;If similarity &amp;gt;= threshold (default 0.88), it returns the cached response in &lt;strong&gt;14ms&lt;/strong&gt; (Cache HIT ⚡).&lt;/li&gt;
&lt;li&gt;If it's a Cache MISS, it forwards the query to OpenAI and stores the new vector.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📊 Benchmark Numbers:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cache MISS (Cold Query)&lt;/strong&gt;: ~1,450 ms | $0.003&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache HIT (Semantically Rephrased)&lt;/strong&gt;: ~14 ms | $0.000 (99% latency reduction)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🔌 2-Line Integration (No Code Rewrite):
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your-openai-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://hypercache-semantic-cache-for-openai-and-llms.p.rapidapi.com/v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The core proxy is completely open-source and auditable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚡ &lt;strong&gt;RapidAPI (500 free calls)&lt;/strong&gt;: &lt;a href="https://rapidapi.com/erdeveshkumardev/api/hypercache-semantic-cache-for-openai-and-llms" rel="noopener noreferrer"&gt;https://rapidapi.com/erdeveshkumardev/api/hypercache-semantic-cache-for-openai-and-llms&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Would love to get feedback on the latency numbers and similarity threshold handling!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>caching</category>
      <category>llm</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
