feat(rag): 优化 vllm 作为 LLM 提供商支持

- 在 RAGEngine 中实现 vllm 提供商的支持
- 添加 OpenAILike 集成用于 vllm 兼容性
- 更新 docker-compose.yml 中的默认 LLM 配置为 vllm
- 添加 llama-index-llms-openai-like 依赖
- 优化同步模块中的文件路径处理逻辑
- 修复 SSH 连接和 SFTP 文件操作的路径兼容性问题
This commit is contained in:
Bennie61 2026-06-11 09:15:39 +08:00
parent 1cb82f4216
commit 8401d90efb
4 changed files with 136 additions and 112 deletions

View File

@ -28,6 +28,7 @@ services:
# ChromaDB 容器默认将数据存储在 /data 目录
- ./chroma_db_data:/data
# 将主机端口映射为可配置(从 .env 读取 CHROMA_SERVER_PORT默认 8002
# 注意以下 8000端口是ChromaDB默认端口不用更改
ports:
- "${CHROMA_SERVER_PORT:-8002}:8000"
environment:
@ -94,6 +95,13 @@ services:
- OLLAMA_MODEL=${OLLAMA_MODEL:-qwen3:1.7b}
- OLLAMA_EMBEDDING_MODEL=${OLLAMA_EMBEDDING_MODEL:-qwen3-embedding:0.6b}
# LLM 配置
# LLM provider: ollama, openai 等
- LLM_PROVIDER=${LLM_PROVIDER:-vllm}
- LLM_BASE_URL=${LLM_BASE_URL:-http://172.20.32.236:8000/v1}
- LLM_MODEL=${LLM_MODEL:-MiniMax-M2.7}
- LLM_API_KEY=${LLM_API_KEY:-none} # 如使用openai等需要API Key的服务
# RAG 配置
- EMBEDDING_DIMENSION=${EMBEDDING_DIMENSION:-768}
- CHUNK_SIZE=${CHUNK_SIZE:-1024}

View File

@ -200,6 +200,17 @@ class RAGEngine:
temperature=self._temperature,
timeout=self._request_timeout,
)
elif provider == "vllm":
from llama_index.llms.openai_like import OpenAILike
self.llm = OpenAILike(
model=model,
api_base=base_url,
api_key=api_key or "none",
is_chat_model=True,
context_window=128000,
temperature=self._temperature,
timeout=self._request_timeout,
)
else:
self.llm = Ollama(
model=model,

View File

@ -43,3 +43,5 @@ markdown2>=2.5.4 # Markdown parsing
paramiko>=3.4.0 # For SSH/SCP functionality
requests~=2.32.5
llama-index-llms-openai-like>=0.2.0

View File

@ -1,5 +1,6 @@
"""Folder synchronization implementation for local and remote folders"""
import os
import posixpath
import re
from typing import List, Dict, Any, Set
from datetime import datetime
@ -309,7 +310,8 @@ class FolderSync(BaseSync):
items = self._sftp_client.listdir_attr(folder_path)
for item in items:
item_path = os.path.join(folder_path, item.filename)
# old:relative_path = os.path.relpath(file_path, self.config.folder_path)
item_path = posixpath.join(folder_path, item.filename)
if item.filename not in ('.', '..'):
if item.st_mode & 0o040000: # Check if it's a directory
@ -336,7 +338,8 @@ class FolderSync(BaseSync):
return False
# Get relative path from folder root
relative_path = os.path.relpath(file_path, self.config.folder_path)
# old: relative_path = os.path.relpath(file_path, self.config.folder_path)
relative_path = posixpath.relpath(file_path, self.config.folder_path)
for pattern in self.config.ignore_patterns:
if self._match_pattern(relative_path, pattern):