<?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 Robert Lukoshko on Medium]]></title>
        <description><![CDATA[Stories by Robert Lukoshko on Medium]]></description>
        <link>https://medium.com/@robert.lukoshko?source=rss-e7ec024b08d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VmstGszGX_l3WCKvpnolqg.jpeg</url>
            <title>Stories by Robert Lukoshko on Medium</title>
            <link>https://medium.com/@robert.lukoshko?source=rss-e7ec024b08d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 00:35:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@robert.lukoshko/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[The Ultimate Guide to Embeddings in Frontend Development]]></title>
            <link>https://medium.com/@robert.lukoshko/the-ultimate-guide-to-embeddings-in-frontend-development-e4211a06bb13?source=rss-e7ec024b08d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4211a06bb13</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Robert Lukoshko]]></dc:creator>
            <pubDate>Wed, 20 Sep 2023 22:04:37 GMT</pubDate>
            <atom:updated>2023-09-20T22:04:37.091Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lygF2rdIgJ16ZDDdz2mfiw.png" /></figure><h3>What Are Embeddings and Why Should You Care?</h3><p>Embeddings are high-dimensional vectors that capture the semantic essence of data. They power features like semantic search and recommendation systems, enhancing user experience by understanding user intent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*TIdN6e0dDEzdCEEEKHUgag.png" /><figcaption>Example of vector visualisation</figcaption></figure><p>How can you implement it?</p><h3>The Traditional Way: Backend-Computed Embeddings</h3><p>Traditionally, embeddings are computed on the backend. The frontend sends data to the backend, which then processes it and returns the embeddings.</p><pre>async function getEmbeddings(text) {<br>  const response = await fetch(&#39;https://your-backend-endpoint.com/embeddings&#39;, {<br>    method: &#39;POST&#39;,<br>    headers: {<br>      &#39;Content-Type&#39;: &#39;application/json&#39;<br>    },<br>    body: JSON.stringify({text: &quot;hello I am text to be embedded&quot;})<br>  });<br>  const data = await response.json();<br>  return data.embeddings;<br>}</pre><p>And at the backend you setup Cloud Solutions like Pinecone and Weaviate. They allow you to store data and search through it inside their clusters.</p><h4>Cloud Vector Databases</h4><p><a href="https://www.pinecone.io/"><strong>Pinecone</strong></a> is a fully managed vector database designed for production applications. It offers high performance and scalability but can get expensive quickly due to its steep price growth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1V91c-OQcS50tO7lX79wGA.png" /><figcaption>Pinecone pricing</figcaption></figure><p><a href="http://weaviate.io/">Weaviate</a>. If you want to go and be more flexible you can use. It is completely open source. You would need to spin up or own cloud instance in docker or kubernetes. Good choice if you know how to quickly do it and are able to set up cloud infrastructure with security correctly.</p><h3>Client side computation</h3><p>New package on NPM which has become extremely popular is <a href="https://github.com/xenova/transformers.js">Transformers.js</a>. It uses ONNX Runtime to run models in the browser. It’s functionally equivalent to Hugging Face’s Python library, supporting common tasks in different modalities. You can easily convert your pretrained PyTorch, TensorFlow, or JAX models to ONNX using 🤗 Optimum.</p><pre>import { pipeline } from &#39;@xenova/transformers&#39;;<br><br>// Allocate a pipeline for sentiment-analysis<br>let pipe = await pipeline(&#39;sentiment-analysis&#39;);<br><br>let out = await pipe(&#39;I love transformers!&#39;);<br>// [{&#39;label&#39;: &#39;POSITIVE&#39;, &#39;score&#39;: 0.999817686}]</pre><p>Straight away from the <strong>frontend</strong>!</p><p>Though the package is still very low level and <strong>misses</strong> <strong>critical</strong> feature like:</p><ul><li>saving data in <strong>permanent storage</strong> on client side</li><li><strong>semantic</strong> search engine</li><li>recommendation engine</li></ul><p>Every developer needs to implement it themselves to make it work.</p><p>But one group of developers created npm package <a href="https://www.npmjs.com/package/client-vector-search">client vector search</a> to simplify this!</p><p>Link to documentation: <a href="https://github.com/xenova/transformers.js">https://github.com/xenova/transformers.js</a></p><h3>Client Vector Search</h3><p>For a more developed high level solution, you can use <a href="https://www.npmjs.com/package/client-vector-search">client vector search</a>. This library allows <strong>semantic search</strong> and stores embeddings in <strong>IndexedDB</strong> for future use.</p><p>Here is how you can implement search in under <strong>8 lines</strong></p><pre>import { getEmbedding, EmbeddingIndex } from &#39;client-vector-search&#39;;<br>const initialObjects = [<br>    { id: 1, name: &quot;Apple&quot;, embedding: getEmbedding(&quot;Apple&quot;)},<br>    { id: 2, name: &quot;Cheddar&quot;, embedding: await getEmbedding(&quot;Cheddar&quot;)},<br>];<br>const index = new EmbeddingIndex(initialObjects); // Creates an index<br>const queryEmbedding = await getEmbedding(&#39;Fruit&#39;); // Query embedding<br>const result = await index.search(queryEmbedding, { topK: 1}); // Returns top similar objects<br>// Apple</pre><h4>Lets break it down step by step</h4><ol><li>Initialize Objects with Embeddings</li></ol><p>The initialObjects array is a collection of objects that you want to index for semantic search. Each object contains an id, a name, and an embedding.</p><p>Code below creates an array of objects, each containing an ID, name, and its corresponding embedding.</p><pre>const initialObjects = [<br>  { id: 1, name: &quot;Refund&quot;, embedding: await getEmbedding(&quot;Refund&quot;) },<br>  { id: 2, name: &quot;Technical Issue&quot;, embedding: await getEmbedding(&quot;Technical Issue&quot;) },<br>];</pre><p>Any object with an embedding property can be indexed. This means you’re not limited to the structure shown; you can add more properties to the object as needed</p><p>2. Create an Embedding Index:</p><pre>const index = new EmbeddingIndex(initialObjects);</pre><p>Initialize the EmbeddingIndex with the array of objects. This creates an index for quick searching.</p><p>3. Generate Query Embedding:</p><pre>const queryEmbedding = await getEmbedding(&#39;Fruit&#39;);</pre><p>Generate an embedding for the query term ‘Fruit’ using the getEmbedding function. The output is an array</p><p>4. Perform the Search:</p><pre>const results = await index.search(queryEmbedding, { topK: 1});</pre><p>Search the index for the top 1object that is most similar to the query embedding.</p><h3>Advanced usage</h3><h4>Caching Data on the Client Side with IndexedDB</h4><p>The code snippet below shows how to <strong>cache</strong> the data on the <strong>client side</strong> using <strong>IndexedDB</strong>. This is particularly useful for <strong>speeding up</strong> future searches and <strong>reducing</strong> computational load.</p><pre>await index.saveIndex(<br>&quot;indexedDB&quot;, <br>  {<br>    DBName: &quot;clientVectorDB&quot;,<br>    objectStoreName:&quot;ClientEmbeddingStore&quot;<br>  }<br>)</pre><p>How It Works?</p><ul><li><strong>Initial Save</strong>: The first time this code runs, it will create a new IndexedDB database and object store with the specified names if they don’t already exist.</li><li><strong>Subsequent Saves</strong>: If the database and object store already exist, the function will update the existing index with any new data.</li><li><strong>Data Persistence</strong>: IndexedDB is a low-level API for storing large amounts of structured data, including files and blobs.</li></ul><h4>Search inside IndexedDB</h4><pre>const results = await index.search(queryEmbedding, {<br>  topK: 5,<br>  useStorage: &quot;indexedDB&quot;,<br>  storageOptions: { // only if you want to override the default options, defaults are below<br>    indexedDBName: &#39;clientVectorDB&#39;,<br>    indexedDBObjectStoreName: &#39;ClientEmbeddingStore&#39;<br>  }<br>});</pre><h3>Coming Soon Features in Client Vector Search</h3><p>Here’s a sneak peek at how you might use this feature in the future:</p><pre>// Initialize the cold storage sync with custom cloud<br>await index.enableColdStorageSync({<br>  cloudProvider: &#39;AWS&#39;,<br>  customSyncFunctions: {<br>    upload: async (data) =&gt; {<br>      // Your custom upload function to your cloud<br>    },<br>    download: async () =&gt; {<br>      // Your custom download function from your cloud<br>    }<br>  }<br>});<br><br>// Trigger a custom sync operation<br>await index.syncToCloud();<br><br>// Load from custom cloud storage into IndexedDB<br>await index.loadFromCloud();</pre><h3>How to get started?</h3><p>For more detailed information, check out the <a href="https://www.npmjs.com/package/client-vector-search">official documentation</a></p><p><a href="https://www.npmjs.com/package/client-vector-search">client-vector-search</a></p><p>Connect with us on Twitter [X]</p><p><a href="https://twitter.com/Karmedge">https://twitter.com/Karmedge</a> &amp; <a href="https://twitter.com/yusufhilmi_">https://twitter.com/yusufhilmi_</a></p><p>built by <a href="https://searchbase.app/">Searchbase</a> team</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*6IPoax0vfkXHdjfEDCyV4g.png" /><figcaption><a href="http://searchbase.app/">searchbase.app</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4211a06bb13" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>