<?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: Veli EROGLU</title>
    <description>The latest articles on DEV Community by Veli EROGLU (@iamnotagentleman).</description>
    <link>https://dev.to/iamnotagentleman</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F505200%2F2435d940-0b84-49a3-a18c-d0985e3bd14c.png</url>
      <title>DEV Community: Veli EROGLU</title>
      <link>https://dev.to/iamnotagentleman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamnotagentleman"/>
    <language>en</language>
    <item>
      <title>Enhance Your RAG Application With Web Searching Capability!</title>
      <dc:creator>Veli EROGLU</dc:creator>
      <pubDate>Sun, 08 Sep 2024 22:57:02 +0000</pubDate>
      <link>https://dev.to/iamnotagentleman/enhance-your-rag-application-with-web-searching-capability-lnn</link>
      <guid>https://dev.to/iamnotagentleman/enhance-your-rag-application-with-web-searching-capability-lnn</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;When building fun projects with Retrieval-Augmented Generation (RAG) applications, we often face limitations like browsing restrictions, making it hard to get the latest information or current data, like weather updates (i hope something more funny). To solve this, we can equip our RAG application with tools to search the internet. Let’s dive in!&lt;/p&gt;

&lt;h2&gt;
  
  
   Our Tool-bench
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;LangChain (Framework for building applications with large language models)&lt;/li&gt;
&lt;li&gt;SearXNG (free metasearch engine)&lt;/li&gt;
&lt;li&gt;CPython (a C language wrapper :&amp;gt; )&lt;/li&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;First we start with the &lt;code&gt;SearXNG&lt;/code&gt; installation.&lt;/p&gt;

&lt;p&gt;1 -) Get SearXNG-docker&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git clone https://github.com/searxng/searxng-docker.git&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2 -) Edit the &lt;code&gt;.env&lt;/code&gt; file to set the hostname and an email&lt;/p&gt;

&lt;p&gt;3 -) Generate the secret key&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Linux&amp;gt;

sed -i "s|ultrasecretkey|$(openssl rand -hex 32)|g" searxng/settings.yml

&amp;lt;MacOS&amp;gt;
sed -i"" -e "s|ultrasecretkey|$(openssl rand -hex 32)|g" searxng/settings.yml 

&amp;lt;Windows&amp;gt;
$randomBytes = New-Object byte[] 32
(New-Object Security.Cryptography.RNGCryptoServiceProvider).GetBytes($randomBytes)
$secretKey = -join ($randomBytes | ForEach-Object { "{0:x2}" -f $_ })
(Get-Content searxng/settings.yml) -replace 'ultrasecretkey', $secretKey | Set-Content searxng/settings.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4 -) Update the &lt;code&gt;searxng/settings.yml&lt;/code&gt; to enable available search formats and disable the limiter for our LangChain instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use_default_settings: true
server:
  # base_url is defined in the SEARXNG_BASE_URL environment variable, see .env and docker-compose.yml
  secret_key: "&amp;lt;secret-key&amp;gt;"  # change this!
  limiter: false
  image_proxy: true
ui:
  static_use_hash: true
redis:
  url: redis://redis:6379/0

search:
    formats:
        - html
        - json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5-) Run SearXNG Instance&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker compose up&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Check the SearXNG deployment in Docker. If everything looks good, you’re ready to continue.&lt;/p&gt;

&lt;h2&gt;
  
  
   Demo Application
&lt;/h2&gt;

&lt;p&gt;1 -) Create a virtual environment &amp;amp; activate&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 -m venv .venv
source .venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2 -) Install Langchain&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install langchain langchain-community
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3 -) Create main.py&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## Simple Get Results
from langchain_community.utilities import SearxSearchWrapper
import pprint

s = SearxSearchWrapper(searx_host="http://localhost:8080",)
result = s.results("What is RAG?", num_results=10, engines=["google"])
pprint.pprint(result)

## Github Tool

from langchain_community.tools.searx_search.tool import SearxSearchResults

wrapper = SearxSearchWrapper(searx_host="**")
github_tool = SearxSearchResults(name="Github", wrapper=wrapper,
                            kwargs = {
                                "engines": ["github"],
                                })

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it! Your RAG application now has search capabilities. This guide doesn’t introduce anything new but aims to bring together the steps for adding web searching functionality to your RAG application. I hope it helps!&lt;/p&gt;

</description>
      <category>rag</category>
      <category>ai</category>
      <category>langchain</category>
      <category>python</category>
    </item>
  </channel>
</rss>
