搜索
首页后端开发Python教程通过 Web 搜索功能增强您的 RAG 应用程序!

Enhance Your RAG Application With Web Searching Capability!

介绍

当使用检索增强生成(RAG)应用程序构建有趣的项目时,我们经常面临浏览限制等限制,这使得很难获取最新信息或当前数据,例如天气更新(我希望有更有趣的东西)。为了解决这个问题,我们可以为 RAG 应用程序配备搜索互联网的工具。让我们开始吧!

 我们的工具台

  • LangChain(使用大型语言模型构建应用程序的框架)
  • SearXNG(免费元搜索引擎)
  • CPython(C 语言包装器 :> )
  • Docker(一个拿着凉面包的男人)

设置

首先我们从 SearXNG 安装开始。

1 -) 获取 SearXNG-docker

git 克隆 https://github.com/searxng/searxng-docker.git

2 -) 编辑 .env 文件以设置主机名和电子邮件

3 -) 生成密钥

<linux>

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

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

<windows>
$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
</windows></macos></linux>

4 -) 更新searxng/settings.yml以启用可用的搜索格式并禁用我们的LangChain实例的限制器:

use_default_settings: true
server:
  # base_url is defined in the SEARXNG_BASE_URL environment variable, see .env and docker-compose.yml
  secret_key: "<secret-key>"  # change this!
  limiter: false
  image_proxy: true
ui:
  static_use_hash: true
redis:
  url: redis://redis:6379/0

search:
    formats:
        - html
        - json
</secret-key>

5-) 运行 SearXNG 实例

docker 组成

检查 Docker 中的 SearXNG 部署。如果一切看起来都不错,您就可以继续了。

 演示应用程序

1 -) 创建虚拟环境并激活

python3 -m venv .venv
source .venv/bin/activate

2 -) 安装 Langchain

pip install langchain langchain-community

3 -) 创建 main.py

## 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"],
                                })

就是这样!您的 RAG 应用程序现在具有搜索功能。本指南没有介绍任何新内容,而是旨在汇总向 RAG 应用程序添加 Web 搜索功能的步骤。希望对您有帮助!

以上是通过 Web 搜索功能增强您的 RAG 应用程序!的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
为什么数组通常比存储数值数据列表更高?为什么数组通常比存储数值数据列表更高?May 05, 2025 am 12:15 AM

ArraySareAryallyMoremory-Moremory-forigationDataDatueTotheIrfixed-SizenatureAntatureAntatureAndirectMemoryAccess.1)arraysStorelelementsInAcontiguxufulock,ReducingOveringOverheadHeadefromenterSormetormetAdata.2)列表,通常

如何将Python列表转换为Python阵列?如何将Python列表转换为Python阵列?May 05, 2025 am 12:10 AM

ToconvertaPythonlisttoanarray,usethearraymodule:1)Importthearraymodule,2)Createalist,3)Usearray(typecode,list)toconvertit,specifyingthetypecodelike'i'forintegers.Thisconversionoptimizesmemoryusageforhomogeneousdata,enhancingperformanceinnumericalcomp

您可以将不同的数据类型存储在同一Python列表中吗?举一个例子。您可以将不同的数据类型存储在同一Python列表中吗?举一个例子。May 05, 2025 am 12:10 AM

Python列表可以存储不同类型的数据。示例列表包含整数、字符串、浮点数、布尔值、嵌套列表和字典。列表的灵活性在数据处理和原型设计中很有价值,但需谨慎使用以确保代码的可读性和可维护性。

Python中的数组和列表之间有什么区别?Python中的数组和列表之间有什么区别?May 05, 2025 am 12:06 AM

Pythondoesnothavebuilt-inarrays;usethearraymoduleformemory-efficienthomogeneousdatastorage,whilelistsareversatileformixeddatatypes.Arraysareefficientforlargedatasetsofthesametype,whereaslistsofferflexibilityandareeasiertouseformixedorsmallerdatasets.

通常使用哪种模块在Python中创建数组?通常使用哪种模块在Python中创建数组?May 05, 2025 am 12:02 AM

theSostCommonlyusedModuleForCreatingArraysInpyThonisnumpy.1)NumpyProvidEseffitedToolsForarrayOperations,Idealfornumericaldata.2)arraysCanbeCreatedDusingsnp.Array()for1dand2Structures.3)

您如何将元素附加到Python列表中?您如何将元素附加到Python列表中?May 04, 2025 am 12:17 AM

toAppendElementStoApythonList,usetheappend()方法forsingleements,Extend()formultiplelements,andinsert()forspecificpositions.1)useeAppend()foraddingoneOnelementAttheend.2)useextendTheEnd.2)useextendexendExendEnd(

您如何创建Python列表?举一个例子。您如何创建Python列表?举一个例子。May 04, 2025 am 12:16 AM

TocreateaPythonlist,usesquarebrackets[]andseparateitemswithcommas.1)Listsaredynamicandcanholdmixeddatatypes.2)Useappend(),remove(),andslicingformanipulation.3)Listcomprehensionsareefficientforcreatinglists.4)Becautiouswithlistreferences;usecopy()orsl

讨论有效存储和数值数据的处理至关重要的实际用例。讨论有效存储和数值数据的处理至关重要的实际用例。May 04, 2025 am 12:11 AM

金融、科研、医疗和AI等领域中,高效存储和处理数值数据至关重要。 1)在金融中,使用内存映射文件和NumPy库可显着提升数据处理速度。 2)科研领域,HDF5文件优化数据存储和检索。 3)医疗中,数据库优化技术如索引和分区提高数据查询性能。 4)AI中,数据分片和分布式训练加速模型训练。通过选择适当的工具和技术,并权衡存储与处理速度之间的trade-off,可以显着提升系统性能和可扩展性。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中