PDF问答聊天机器人

基于RAG技术的聊天机器人,通过语义搜索和Groq托管的LLM从PDF文档中提取信息并回答问题。

  • by mayankbisht-tech
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 mayankbisht-tech/MCP

使用说明

# 基于RAG的聊天机器人

一个最小的RAG(检索增强生成)聊天机器人,使用语义搜索和Groq托管的LLM根据PDF文档回答问题。

设置

  1. 克隆仓库

  2. 创建虚拟环境并安装依赖关系:

python -m venv .venv
.venv\Scripts\activate  # Windows
pip install -r requirements.txt
  1. 将API密钥添加到 .env:
GROQ_API_KEY="your-groq-api-key"
  1. 将您的PDF文件添加到 rag/books/ 文件夹

  2. 为文件编制索引:

cd rag
python vector_store.py
cd ..
  1. 运行聊天机器人:
python rag/reteriver.py

用法

键入您的问题,机器人将根据索引的PDF文档进行回答。类型 exit 或 quit 停止。

项目结构

├── rag/
│   ├── books/          # Place your PDF files here
│   ├── loader.py       # PDF loading
│   ├── chunker.py      # Text chunking
│   ├── embedder.py     # Embedding utilities
│   ├── vector_store.py # Document indexing
│   ├── model_config.py # LLM provider/model settings
│   └── reteriver.py    # Chatbot interface
├── requirements.txt
└── README.md

备注

  • 这 qdrant_data/ 运行时会自动创建文件夹 vector_store.py
  • 你需要重新运行 vector_store.py 每当您添加新的PDF文件时
  • 在新设备上,将PDF添加到 rag/books/ 并运行索引步骤