LangChain-SearXNG
AI Q&A Search Engine ➡️ 基于LangChain和SearXNG打造的开源AI搜索引擎
Stars: 83
LangChain-SearXNG is an open-source AI search engine built on LangChain and SearXNG. It supports faster and more accurate search and question-answering functionalities. Users can deploy SearXNG and set up Python environment to run LangChain-SearXNG. The tool integrates AI models like OpenAI and ZhipuAI for search queries. It offers two search modes: Searxng and ZhipuWebSearch, allowing users to control the search workflow based on input parameters. LangChain-SearXNG v2 version enhances response speed and content quality compared to the previous version, providing a detailed configuration guide and showcasing the effectiveness of different search modes through comparisons.
README:
简体中文 | English
基于LangChain和SearXNG打造的开源AI搜索引擎
🌟🌟🌟
重要更新: LangChain-SearXNG 支持 Docker 部署, 支持 docker-compose 一键部署体验🚀🔥💥
🌟🌟🌟
🛫 项目支持三种部署方式,可以按需选取
- docker-compose 部署
- 分开 SearXNG 和 LangChain-SearXNG Docker 部署
- 手动部署
由于 SearXNG 需要访问外网,建议部署准备好外网环境
- 拉取项目完整代码
git clone https://github.com/ptonlix/LangChain-SearXNG.git --recursive
cd LangChain-SearXNG/searxng-docker
# 录入邮箱,域名可不配置
vim .env
# 修改searxng配置文件
vim searxng/settings.yml
# 修改 secret_key
openssl rand -hex 32 # 生成密钥填入
# 修改 limiter 和search,其它参数保持原配置文件不变
# see https://docs.searxng.org/admin/settings/settings.html#settings-use-default-settings
use_default_settings: true
server:
limiter: false # can be disabled for a private instance
search:
formats:
- html
- json
- 新增配置文件 settings-pro.yaml
详情可以参考配置文件介绍
配置文件修改
- 启动 docker
cd LangChain-SearXNG
docker compose up
由于 SearXNG 需要访问外网,建议部署选择外网服务器 以下部署示例选择以腾讯云轻量服务器-Centos 系统为例
根据 searxng-docker教程,按照以下操作,容器化部署 SearXNG
# 拉取代码
git clone https://github.com/searxng/searxng-docker.git
cd searxng-docker
# 修改域名和录入邮箱
vim .env
# 其余配置同上docker-compose 部署
- 拉取镜像
docker pull ptonlix/langchain-searxng:v0.1.8
#通过外部配置文件挂载启动容器
docker run -p 8002:8002 -p 8501:8501 \
-v ./settings-pro.yaml:/app/config/settings.yaml \
--name langchain-searxng \
langchain-searxng:v0.1.8
- 配置文件 settings-pro.yaml
详情可以参考配置文件介绍
配置文件修改
- 访问 WebUI
- 安装 miniconda
mkdir ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
~/miniconda3/bin/conda init bash
- 创建虚拟环境
# 创建环境
conda create -n LangChain-SearXNG python==3.10.11
- 安装 poetry
# 安装
curl -sSL https://install.python-poetry.org | python3 -
- 安装依赖
# 克隆项目代码到本地
git clone https://github.com/ptonlix/LangChain-SearXNG.git
conda activate LangChain-SearXNG # 激活环境
cd LangChain-SearXNG # 进入项目
poetry install # 安装依赖
OpenAI 文档
ZhipuAI 文档
DeepSeek 文档
LangSmith API
# settings.yaml
配置文件录入或通过环境变量设置以下变量,建议配置三个大模型API,在体验时可以自由选择模型来体验
# 根据自身环境选择合适的 大模型API
# OPENAI 大模型API
OPENAI_API_BASE
OPENAI_API_KEY
# ZHIPUAI 智谱API
ZHIPUAI_API_KEY
ZHIPUAI_API_BASE
# DeepSeek 大模型API
DEEPSPEAK_API_KEY
DEEPSPEAK_API_BASE
# LangChain调试 API
LANGCHAIN_API_KEY
# SearXNG请求地址,docker-compose 部署无需修改该变量
SEARX_HOST
详情配置文件介绍见: LangChain-SearXNG 配置
# 启动项目
python -m langchain_searxng
# 查看API
访问: http://localhost:8002/docs 获取 API 信息
# 启动前端页面
cd webui
streamlit run webui.py
- 搜索问答模式
目前项目搜索 API 已升级到 v2 版本,下面例子请求使用 v2 版本进行体验
请求参数:
{
"question": "目前中国新能源汽车厂商排行榜是什么", #提问问题
"chat_history": [], #历史聊天记录
"network": true, #是否开启联网
"conversation_id": "", #提问的UUID
"llm": "zhipuai", #采用的大模型
"retriever": "searx" # 采用的召回模式
}
目前支持两种搜索模式 Searxng
和 智谱WebSearch
,这两种模式启用主要根据输入的请求参数llm
h 和retriever
控制
I. 开启 智谱 WebSearch
对应 Webui 页面 ➡️ 智谱搜索
{
...
"llm": "zhipuwebsearch", #大模型必须选择zhipuwebsearch (智谱搜索定制模型)
"retriever": "zhipuwebsearch" #召回模式选择 zhipuwebsearch
}
Ⅱ. 开启 AI+SearXNG V2 版本
对应 Webui 页面 ➡️ SearXNG 搜索
{
...
"llm": "deepseek", #可选:默认openai,可选zhipuai,可选deepseek
"retriever": "searx" #可选:默认searx
}
🎨 能力 | AI+SearXNGv1 | AI+SearXNGv2 | 智谱 WebSearch | 360AI 搜索 |
---|---|---|---|---|
🚀 响应速度 | 🌟🌟🌟 | 🌟🌟🌟🌟 | 🌟🌟🌟🌟🌟 | 🌟🌟🌟🌟 |
📝 内容质量 | 🌟🌟🌟 | 🌟🌟🌟🌟 | 🌟🌟🌟 | 🌟🌟🌟🌟🌟 |
💦 流式响应 | 1. 搜索过程支持 2.搜索结果支持 |
1. 搜索过程支持 2.搜索结果支持 |
1. 搜索过程不支持 2.搜索结果支持 |
1. 搜索过程支持 2.搜索结果支持 |
AI+SearXNGv2
相较于上个版本从响应速度和内容质量均有明显提升,距离 360AI 搜索更进一步了 💪
详细评测分析: AI 搜索模式对比测试
本项目通过构建 SearXNG 搜索引擎 Tool + LangChain LCEL 调用方式构建-AI 搜索引擎 Agent,以 Fastapi 对外提供服务
-
通过用户输入的参数控制搜索工作流程,主流程分为
联网搜索问答
和模型内搜索问答
-
模型内搜索问答
: 通过获取用户输入chat_history
question
构建 Prompt 输入到 LLM 生成问答结果并返回 -
联网搜索问答
: 主要分为三个部分condense question chain
搜索召回
response synthesizer chain
- 如果输入的 chat_history 不为空,则进入
condense question chain
工作流,根据聊天上下文生成最合适的搜索 query - 通过 query 进入
搜索召回
工作流:分为searxng search
select search result
Data processing
三个部分
- 通过 LLM 根据搜索 query 选择最合适的 searxng 搜索参数,调用 searxng api 搜索结果(通常 20 ~ 30 个搜索结果)
- 再根据上一步搜索到的结果,通过 LLM 进一步筛选出最合适回答该 query 的搜索结果,通常 6 个
- 根据确定最合适的搜索结果,进行数据处理:检查可访问性->获取 html->生成 Documents ->format 格式化,最终输出问答上下文
context
- 通过
搜索召回
的上下文context
和用户输入的chat_history
question
一起进入response synthesizer chain
工作流,最终生成搜索响应
- 如果输入的 chat_history 不为空,则进入
v2 对比 v1 版本的差别
- v1 版本主要是搜索获取数据,再通过过滤筛选出最佳数据,但如果一开始源数据质量不佳,则后续工作效果就会大减,而且基础源数据数量不多,向量化过滤时间很长。
- v2 版本一个主要原则是确保源数据质量,搜索结果尽可能符合搜索关键字,所以精心构建了搜索召回工作流,让大模型参与获取最佳搜索结果。同时由于已经筛选出最佳搜索数据,不需要向量化过滤,可以直接 LLM 让生成结果。(Token 越来越便宜也是一大趋势)
- v2 版本还优化了搜索网页加载流程,尽可能快的获取到搜索数据
- v2 版本增加搜索过程可视化,在流式返回中,可以动态显示搜索进度,展示更丰富的内容
├── docs # 文档
├── langchain_searxng
│ ├── components #自定义组件
│ ├── server # API服务
│ ├── settings # 配置服务
│ ├── utils
│ ├── constants.py
│ ├── di.py
│ ├── launcher.py
│ ├── main.py
│ ├── paths.py
│ ├── __init__.py
│ ├── __main__.py #入口
│ └── __version__.py
├── log # 日志目录
├── wwebui # 前端展示页面
- 支持查询结果 http sse 流式和非流式(整体)返回
- 支持联网查询 QA 和直接 QA 切换
- 支持 Token 计算(含 embedding)
- 支持 openai、zhipuai、deepseek 三种大模型
- 支持 配置文件动态加载
- 支持 智谱 AI 新推出的 WebSearch 功能
- [x] 搭建 LangChain-SearXNG 初步框架,完善基本功能
- [x] 支持配置文件动态加载,方便更改相关参数
- [x] 完善 网站页面内容爬取效果
- [x] 支持网络访问异常处理,方便国内环境使用
- [x] 支持智谱 WebSearch 功能
- [x] 升级 SearXNG 搜索问题,支持更快更精准的回答
- [x] 搭建前端 Web Demo
- [ ] Docker 化项目,便于部署传播
- [x] 支持视频搜索
- [ ] 优化 Prompt,支持输出更丰富的内容
🎉 扫码联系作者,如果你也对本项目感兴趣
🎉 欢迎加入 LangChain-X (帝阅开发社区) 项目群参与讨论交流
欢迎大家贡献力量,一起共建 LangChain-SearXNG,您可以做任何有益事情
- 报告错误
- 建议改进
- 文档贡献
- 代码贡献
...
👏👏👏
「帝阅」
是一款个人专属知识管理与创造的 AI Native 产品
为用户打造一位专属的侍读助理,帮助提升用户获取知识效率和发挥创造力
让用户更好地去积累知识、管理知识、运用知识
LangChain-SearXNG 是帝阅项目一个子项目,我们决定开源出来,与大家交流学习
同时,欢迎大家前往体验帝阅 给我们提出宝贵的建议
For Tasks:
Click tags to check more tools for each tasksFor Jobs:
Alternative AI tools for LangChain-SearXNG
Similar Open Source Tools
LangChain-SearXNG
LangChain-SearXNG is an open-source AI search engine built on LangChain and SearXNG. It supports faster and more accurate search and question-answering functionalities. Users can deploy SearXNG and set up Python environment to run LangChain-SearXNG. The tool integrates AI models like OpenAI and ZhipuAI for search queries. It offers two search modes: Searxng and ZhipuWebSearch, allowing users to control the search workflow based on input parameters. LangChain-SearXNG v2 version enhances response speed and content quality compared to the previous version, providing a detailed configuration guide and showcasing the effectiveness of different search modes through comparisons.
chatgpt-web
ChatGPT Web is a web application that provides access to the ChatGPT API. It offers two non-official methods to interact with ChatGPT: through the ChatGPTAPI (using the `gpt-3.5-turbo-0301` model) or through the ChatGPTUnofficialProxyAPI (using a web access token). The ChatGPTAPI method is more reliable but requires an OpenAI API key, while the ChatGPTUnofficialProxyAPI method is free but less reliable. The application includes features such as user registration and login, synchronization of conversation history, customization of API keys and sensitive words, and management of users and keys. It also provides a user interface for interacting with ChatGPT and supports multiple languages and themes.
Streamer-Sales
Streamer-Sales is a large model for live streamers that can explain products based on their characteristics and inspire users to make purchases. It is designed to enhance sales efficiency and user experience, whether for online live sales or offline store promotions. The model can deeply understand product features and create tailored explanations in vivid and precise language, sparking user's desire to purchase. It aims to revolutionize the shopping experience by providing detailed and unique product descriptions to engage users effectively.
wechat-bot
WeChat Bot is a simple and easy-to-use WeChat robot based on chatgpt and wechaty. It can help you automatically reply to WeChat messages or manage WeChat groups/friends. The tool requires configuration of AI services such as Xunfei, Kimi, or ChatGPT. Users can customize the tool to automatically reply to group or private chat messages based on predefined conditions. The tool supports running in Docker for easy deployment and provides a convenient way to interact with various AI services for WeChat automation.
langchain4j-aideepin-web
The langchain4j-aideepin-web repository is the frontend project of langchain4j-aideepin, an open-source, offline deployable retrieval enhancement generation (RAG) project based on large language models such as ChatGPT and application frameworks such as Langchain4j. It includes features like registration & login, multi-sessions (multi-roles), image generation (text-to-image, image editing, image-to-image), suggestions, quota control, knowledge base (RAG) based on large models, model switching, and search engine switching.
meet-libai
The 'meet-libai' project aims to promote and popularize the cultural heritage of the Chinese poet Li Bai by constructing a knowledge graph of Li Bai and training a professional AI intelligent body using large models. The project includes features such as data preprocessing, knowledge graph construction, question-answering system development, and visualization exploration of the graph structure. It also provides code implementations for large models and RAG retrieval enhancement.
AMchat
AMchat is a large language model that integrates advanced math concepts, exercises, and solutions. The model is based on the InternLM2-Math-7B model and is specifically designed to answer advanced math problems. It provides a comprehensive dataset that combines Math and advanced math exercises and solutions. Users can download the model from ModelScope or OpenXLab, deploy it locally or using Docker, and even retrain it using XTuner for fine-tuning. The tool also supports LMDeploy for quantization, OpenCompass for evaluation, and various other features for model deployment and evaluation. The project contributors have provided detailed documentation and guides for users to utilize the tool effectively.
NarratoAI
NarratoAI is an automated video narration tool that provides an all-in-one solution for script writing, automated video editing, voice-over, and subtitle generation. It is powered by LLM to enhance efficient content creation. The tool aims to simplify the process of creating film commentary and editing videos by automating various tasks such as script writing and voice-over generation. NarratoAI offers a user-friendly interface for users to easily generate video scripts, edit videos, and customize video parameters. With future plans to optimize story generation processes and support additional large models, NarratoAI is a versatile tool for content creators looking to streamline their video production workflow.
chatgpt-web-sea
ChatGPT Web Sea is an open-source project based on ChatGPT-web for secondary development. It supports all models that comply with the OpenAI interface standard, allows for model selection, configuration, and extension, and is compatible with OneAPI. The tool includes a Chinese ChatGPT tuning guide, supports file uploads, and provides model configuration options. Users can interact with the tool through a web interface, configure models, and perform tasks such as model selection, API key management, and chat interface setup. The project also offers Docker deployment options and instructions for manual packaging.
Chat-Style-Bot
Chat-Style-Bot is an intelligent chatbot designed to mimic the chatting style of a specified individual. By analyzing and learning from WeChat chat records, Chat-Style-Bot can imitate your unique chatting style and become your personal chat assistant. Whether it's communicating with friends or handling daily conversations, Chat-Style-Bot can provide a natural, personalized interactive experience.
aipan-netdisk-search
Aipan-Netdisk-Search is a free and open-source web project for searching netdisk resources. It utilizes third-party APIs with IP access restrictions, suggesting self-deployment. The project can be easily deployed on Vercel and provides instructions for manual deployment. Users can clone the project, install dependencies, run it in the browser, and access it at localhost:3001. The project also includes documentation for deploying on personal servers using NUXT.JS. Additionally, there are options for donations and communication via WeChat.
moonpalace
MoonPalace is a debugging tool for API provided by Moonshot AI. It supports all platforms (Mac, Windows, Linux) and is simple to use by replacing 'base_url' with 'http://localhost:9988'. It captures complete requests, including 'accident scenes' during network errors, and allows quick retrieval and viewing of request information using 'request_id' and 'chatcmpl_id'. It also enables one-click export of BadCase structured reporting data to help improve Kimi model capabilities. MoonPalace is recommended for use as an API 'supplier' during code writing and debugging stages to quickly identify and locate various issues related to API calls and code writing processes, and to export request details for submission to Moonshot AI to improve Kimi model.
fastllm
FastLLM is a high-performance large model inference library implemented in pure C++ with no third-party dependencies. Models of 6-7B size can run smoothly on Android devices. Deployment communication QQ group: 831641348
GitHubSentinel
GitHub Sentinel is an intelligent information retrieval and high-value content mining AI Agent designed for the era of large models (LLMs). It is aimed at users who need frequent and large-scale information retrieval, especially open source enthusiasts, individual developers, and investors. The main features include subscription management, update retrieval, notification system, report generation, multi-model support, scheduled tasks, graphical interface, containerization, continuous integration, and the ability to track and analyze the latest dynamics of GitHub open source projects and expand to other information channels like Hacker News for comprehensive information mining and analysis capabilities.
ChatPilot
ChatPilot is a chat agent tool that enables AgentChat conversations, supports Google search, URL conversation (RAG), and code interpreter functionality, replicates Kimi Chat (file, drag and drop; URL, send out), and supports OpenAI/Azure API. It is based on LangChain and implements ReAct and OpenAI Function Call for agent Q&A dialogue. The tool supports various automatic tools such as online search using Google Search API, URL parsing tool, Python code interpreter, and enhanced RAG file Q&A with query rewriting support. It also allows front-end and back-end service separation using Svelte and FastAPI, respectively. Additionally, it supports voice input/output, image generation, user management, permission control, and chat record import/export.
CareGPT
CareGPT is a medical large language model (LLM) that explores medical data, training, and deployment related research work. It integrates resources, open-source models, rich data, and efficient deployment methods. It supports various medical tasks, including patient diagnosis, medical dialogue, and medical knowledge integration. The model has been fine-tuned on diverse medical datasets to enhance its performance in the healthcare domain.
For similar tasks
LangChain-SearXNG
LangChain-SearXNG is an open-source AI search engine built on LangChain and SearXNG. It supports faster and more accurate search and question-answering functionalities. Users can deploy SearXNG and set up Python environment to run LangChain-SearXNG. The tool integrates AI models like OpenAI and ZhipuAI for search queries. It offers two search modes: Searxng and ZhipuWebSearch, allowing users to control the search workflow based on input parameters. LangChain-SearXNG v2 version enhances response speed and content quality compared to the previous version, providing a detailed configuration guide and showcasing the effectiveness of different search modes through comparisons.
For similar jobs
sweep
Sweep is an AI junior developer that turns bugs and feature requests into code changes. It automatically handles developer experience improvements like adding type hints and improving test coverage.
teams-ai
The Teams AI Library is a software development kit (SDK) that helps developers create bots that can interact with Teams and Microsoft 365 applications. It is built on top of the Bot Framework SDK and simplifies the process of developing bots that interact with Teams' artificial intelligence capabilities. The SDK is available for JavaScript/TypeScript, .NET, and Python.
ai-guide
This guide is dedicated to Large Language Models (LLMs) that you can run on your home computer. It assumes your PC is a lower-end, non-gaming setup.
classifai
Supercharge WordPress Content Workflows and Engagement with Artificial Intelligence. Tap into leading cloud-based services like OpenAI, Microsoft Azure AI, Google Gemini and IBM Watson to augment your WordPress-powered websites. Publish content faster while improving SEO performance and increasing audience engagement. ClassifAI integrates Artificial Intelligence and Machine Learning technologies to lighten your workload and eliminate tedious tasks, giving you more time to create original content that matters.
chatbot-ui
Chatbot UI is an open-source AI chat app that allows users to create and deploy their own AI chatbots. It is easy to use and can be customized to fit any need. Chatbot UI is perfect for businesses, developers, and anyone who wants to create a chatbot.
BricksLLM
BricksLLM is a cloud native AI gateway written in Go. Currently, it provides native support for OpenAI, Anthropic, Azure OpenAI and vLLM. BricksLLM aims to provide enterprise level infrastructure that can power any LLM production use cases. Here are some use cases for BricksLLM: * Set LLM usage limits for users on different pricing tiers * Track LLM usage on a per user and per organization basis * Block or redact requests containing PIIs * Improve LLM reliability with failovers, retries and caching * Distribute API keys with rate limits and cost limits for internal development/production use cases * Distribute API keys with rate limits and cost limits for students
uAgents
uAgents is a Python library developed by Fetch.ai that allows for the creation of autonomous AI agents. These agents can perform various tasks on a schedule or take action on various events. uAgents are easy to create and manage, and they are connected to a fast-growing network of other uAgents. They are also secure, with cryptographically secured messages and wallets.
griptape
Griptape is a modular Python framework for building AI-powered applications that securely connect to your enterprise data and APIs. It offers developers the ability to maintain control and flexibility at every step. Griptape's core components include Structures (Agents, Pipelines, and Workflows), Tasks, Tools, Memory (Conversation Memory, Task Memory, and Meta Memory), Drivers (Prompt and Embedding Drivers, Vector Store Drivers, Image Generation Drivers, Image Query Drivers, SQL Drivers, Web Scraper Drivers, and Conversation Memory Drivers), Engines (Query Engines, Extraction Engines, Summary Engines, Image Generation Engines, and Image Query Engines), and additional components (Rulesets, Loaders, Artifacts, Chunkers, and Tokenizers). Griptape enables developers to create AI-powered applications with ease and efficiency.