xinli/rag-python/config.py
xiao12feng@outlook.com 0f490298f3 加入AI分析知识库
2025-12-20 12:08:33 +08:00

52 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
RAG 服务配置文件
支持与 jar 包同级目录部署
使用本地 Ollama 进行向量化
"""
import os
import sys
# 服务配置
HOST = "0.0.0.0"
PORT = 5000
# Ollama 配置(使用本地 Ollama 生成向量)
OLLAMA_URL = "http://localhost:11434"
OLLAMA_EMBED_MODEL = "nomic-embed-text" # 你已经下载的嵌入模型
# 获取程序运行目录(支持打包后部署)
# 当与 jar 包同级部署时BASE_DIR 就是 rag-python 文件夹
if getattr(sys, 'frozen', False):
# 如果是打包后的 exe
BASE_DIR = os.path.dirname(sys.executable)
else:
# 正常 Python 运行
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# 文件夹配置 - 都在 rag-python 目录下
KNOWLEDGE_DIR = os.path.join(BASE_DIR, "knowledge_docs") # 知识库文档目录
INDEX_DIR = os.path.join(BASE_DIR, "index_data") # 索引存储目录
UPLOAD_DIR = os.path.join(BASE_DIR, "uploads") # 上传文件临时目录
# 确保目录存在
for dir_path in [KNOWLEDGE_DIR, INDEX_DIR, UPLOAD_DIR]:
os.makedirs(dir_path, exist_ok=True)
# 支持的文件类型
SUPPORTED_EXTENSIONS = {'.txt', '.md', '.pdf', '.docx', '.doc'}
# 文本分块配置
CHUNK_SIZE = 300 # 每个文本块的字符数(减小以适应 nomic-embed-text 的 2048 token 限制)
CHUNK_OVERLAP = 30 # 文本块之间的重叠字符数
# 检索配置
TOP_K = 5 # 返回最相关的文档数量
# 打印配置信息
print(f"[配置] 程序目录: {BASE_DIR}")
print(f"[配置] 知识库目录: {KNOWLEDGE_DIR}")
print(f"[配置] 索引目录: {INDEX_DIR}")
print(f"[配置] Ollama地址: {OLLAMA_URL}")
print(f"[配置] 嵌入模型: {OLLAMA_EMBED_MODEL}")