-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig.py
More file actions
73 lines (60 loc) · 2.15 KB
/
config.py
File metadata and controls
73 lines (60 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
基于图数据库的RAG系统配置文件
"""
from dataclasses import dataclass
from typing import Dict, Any
@dataclass
class GraphRAGConfig:
"""基于图数据库的RAG系统配置类"""
# Neo4j数据库配置
neo4j_uri: str = "bolt://localhost:7687"
neo4j_user: str = "neo4j"
neo4j_password: str = "all-in-rag"
neo4j_database: str = "neo4j"
# Milvus配置
milvus_host: str = "localhost"
milvus_port: int = 19530
milvus_collection_name: str = "cooking_knowledge"
milvus_dimension: int = 512 # BGE-small-zh-v1.5的向量维度
# 模型配置
embedding_model: str = "BAAI/bge-small-zh-v1.5"
llm_model: str = "gpt-4o-mini"
# 检索配置(LightRAG Round-robin策略)
top_k: int = 5
# 生成配置
temperature: float = 0.1
max_tokens: int = 2048
# 图数据处理配置
chunk_size: int = 500
chunk_overlap: int = 50
max_graph_depth: int = 2 # 图遍历最大深度
def __post_init__(self):
"""初始化后的处理"""
# LightRAG使用Round-robin策略,无需权重验证
pass
@classmethod
def from_dict(cls, config_dict: Dict[str, Any]) -> 'GraphRAGConfig':
"""从字典创建配置对象"""
return cls(**config_dict)
def to_dict(self) -> Dict[str, Any]:
"""转换为字典"""
return {
'neo4j_uri': self.neo4j_uri,
'neo4j_user': self.neo4j_user,
'neo4j_password': self.neo4j_password,
'neo4j_database': self.neo4j_database,
'milvus_host': self.milvus_host,
'milvus_port': self.milvus_port,
'milvus_collection_name': self.milvus_collection_name,
'milvus_dimension': self.milvus_dimension,
'embedding_model': self.embedding_model,
'llm_model': self.llm_model,
'top_k': self.top_k,
'temperature': self.temperature,
'max_tokens': self.max_tokens,
'chunk_size': self.chunk_size,
'chunk_overlap': self.chunk_overlap,
'max_graph_depth': self.max_graph_depth
}
# 默认配置实例
DEFAULT_CONFIG = GraphRAGConfig()