avatarLaxfed Paulacy

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1996

Abstract

er hardware.</li></ol><h2 id="f41f">The Project: Implementing Retrieval-Augmented Generation (RAG)</h2><p id="015f">Our goal is to recreate a popular LangChain use-case, Retrieval-Augmented Generation (RAG), using open-source, locally running software. The RAG chain allows users to “chat with their documents,” enabling them to extract information from unstructured data sources.</p><h2 id="0424">Data Ingestion</h2><p id="6947">The first step is to load the data and format it for natural language queries. This involves:</p><ul><li>Splitting a document into semantic chunks</li><li>Creating a vector representation of each chunk using an embeddings model</li><li>Loading the chunks and vectors into a specialized database (vector store)</li></ul><div id="ac43"><pre><span class="hljs-comment">// Sample code for loading and splitting data</span> <span class="hljs-comment">// Load the document</span> <span class="hljs-keyword">const</span> <span class="hljs-built_in">document</span> = <span class="hljs-keyword">await</span> loadDocument(<span class="hljs-string">'example.pdf'</span>);

<span class="hljs-comment">// Split the document into semantic chunks</span> <span class="hljs-keyword">const</span> chunks = splitDocument(<span class="hljs-built_in">document</span>);</pre></div><h2 id="3514">Retrieval and Generation</h2><p id="b4bf">The next step is to query the data to generate responses based on user input. This involves searching the prepared vector store for semantically similar document chunks and using them to guide the LLM to generate a final answer.</p><div id="23d1"><pre><span class="hljs-comment">// Sample code for querying the vector store</span> <span class="hljs-comment">// Search for document chunks similar to the user's query</span> <span class="hljs-keyword">const</span> similarChunks = vectorStore.<span class="hljs-keyword">search</span>(<span class="hljs-keyword">query</span>);</pre></div><h2 id="9b1e">Building the Local Stack</h2><p id="1f34">As part o

Options

f the project, a locally running model, Mistral 7B, is integrated into the web app using Ollama.</p><div id="7111"><pre>// Sample code for running the Mistral model via Ollama // Start the Mistral<span class="hljs-built_in"> instance </span>via Ollama $ ollama run mistral</pre></div><h2 id="98f8">Conclusion and Future Prospects</h2><p id="4616">While powerful, pre-installed LLMs are currently the most feasible solution for web apps, the future may hold possibilities for new browser APIs that allow web apps to request access to locally running LLMs.</p><p id="6882">In this tutorial, we explored the process of building LLM-powered web apps with client-side technology. The use of locally running software and client-side technologies provides cost-effective, privacy-aware, and potentially faster web applications. As open-source models advance and more consumer hardware includes GPUs, the scope for running these models on local hardware is expected to expand.</p><p id="a6d7">For more in-depth details and sample code, you can refer to the demo app and its GitHub repository linked in the article.</p><div id="81b2" class="link-block"> <a href="https://readmedium.com/langchain-can-chatgpt-be-fine-tuned-to-surpass-gpt-4-in-summarization-06e6eb044191"> <div> <div> <h2>LANGCHAIN — Can ChatGPT be Fine-Tuned to Surpass GPT-4 in Summarization?</h2> <div><h3>The function of good software is to make the complex appear to be simple. — Grady Booch</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*nu7ZXSdSXeo6aCLEJYoZpg.jpeg)"></div> </div> </div> </a> </div><p id="1fc2">By embracing local models and client-side technologies, developers can create innovative and privacy-conscious LLM-powered web applications.</p></article></body>

LANGCHAIN — Building LLM-Powered Web Apps with Client-Side Technology

The human spirit must prevail over technology. — Albert Einstein

Building LLM-Powered Web Apps with Client-Side Technology

It’s no secret that machine learning has predominantly been a domain of Python developers. However, with the rise of ChatGPT, many web developers are now venturing into building web apps with machine learning capabilities using JavaScript. In this tutorial, we will explore how to build a web app using LangChain’s open-source, locally running software and client-side technologies.

Why Build LLM-Powered Web Apps with Client-Side Technology?

There are several advantages to building web apps in this manner:

  1. Cost: All compute and inference are done client-side, eliminating the need for additional costs besides hosting.
  2. Privacy: No data needs to leave the user’s local machine, ensuring privacy.
  3. Potential Speed Increases: Client-side operations can reduce HTTP call overhead, although inference speed may be limited by user hardware.

The Project: Implementing Retrieval-Augmented Generation (RAG)

Our goal is to recreate a popular LangChain use-case, Retrieval-Augmented Generation (RAG), using open-source, locally running software. The RAG chain allows users to “chat with their documents,” enabling them to extract information from unstructured data sources.

Data Ingestion

The first step is to load the data and format it for natural language queries. This involves:

  • Splitting a document into semantic chunks
  • Creating a vector representation of each chunk using an embeddings model
  • Loading the chunks and vectors into a specialized database (vector store)
// Sample code for loading and splitting data
// Load the document
const document = await loadDocument('example.pdf');

// Split the document into semantic chunks
const chunks = splitDocument(document);

Retrieval and Generation

The next step is to query the data to generate responses based on user input. This involves searching the prepared vector store for semantically similar document chunks and using them to guide the LLM to generate a final answer.

// Sample code for querying the vector store
// Search for document chunks similar to the user's query
const similarChunks = vectorStore.search(query);

Building the Local Stack

As part of the project, a locally running model, Mistral 7B, is integrated into the web app using Ollama.

// Sample code for running the Mistral model via Ollama
// Start the Mistral instance via Ollama
$ ollama run mistral

Conclusion and Future Prospects

While powerful, pre-installed LLMs are currently the most feasible solution for web apps, the future may hold possibilities for new browser APIs that allow web apps to request access to locally running LLMs.

In this tutorial, we explored the process of building LLM-powered web apps with client-side technology. The use of locally running software and client-side technologies provides cost-effective, privacy-aware, and potentially faster web applications. As open-source models advance and more consumer hardware includes GPUs, the scope for running these models on local hardware is expected to expand.

For more in-depth details and sample code, you can refer to the demo app and its GitHub repository linked in the article.

By embracing local models and client-side technologies, developers can create innovative and privacy-conscious LLM-powered web applications.

Apps
Langchain
Llm Powered
Client Side
ChatGPT
Recommended from ReadMedium