基于图数据库的RAG系统配置类
| 7 | |
| 8 | @dataclass |
| 9 | class GraphRAGConfig: |
| 10 | """基于图数据库的RAG系统配置类""" |
| 11 | |
| 12 | # Neo4j数据库配置 |
| 13 | neo4j_uri: str = "bolt://localhost:7687" |
| 14 | neo4j_user: str = "neo4j" |
| 15 | neo4j_password: str = "all-in-rag" |
| 16 | neo4j_database: str = "neo4j" |
| 17 | |
| 18 | # Milvus配置 |
| 19 | milvus_host: str = "localhost" |
| 20 | milvus_port: int = 19530 |
| 21 | milvus_collection_name: str = "cooking_knowledge" |
| 22 | milvus_dimension: int = 512 # BGE-small-zh-v1.5的向量维度 |
| 23 | |
| 24 | # 模型配置 |
| 25 | embedding_model: str = "BAAI/bge-small-zh-v1.5" |
| 26 | llm_model: str = "gpt-4o-mini" |
| 27 | |
| 28 | # 检索配置(LightRAG Round-robin策略) |
| 29 | top_k: int = 5 |
| 30 | |
| 31 | # 生成配置 |
| 32 | temperature: float = 0.1 |
| 33 | max_tokens: int = 2048 |
| 34 | |
| 35 | # 图数据处理配置 |
| 36 | chunk_size: int = 500 |
| 37 | chunk_overlap: int = 50 |
| 38 | max_graph_depth: int = 2 # 图遍历最大深度 |
| 39 | |
| 40 | def __post_init__(self): |
| 41 | """初始化后的处理""" |
| 42 | # LightRAG使用Round-robin策略,无需权重验证 |
| 43 | pass |
| 44 | |
| 45 | @classmethod |
| 46 | def from_dict(cls, config_dict: Dict[str, Any]) -> 'GraphRAGConfig': |
| 47 | """从字典创建配置对象""" |
| 48 | return cls(**config_dict) |
| 49 | |
| 50 | def to_dict(self) -> Dict[str, Any]: |
| 51 | """转换为字典""" |
| 52 | return { |
| 53 | 'neo4j_uri': self.neo4j_uri, |
| 54 | 'neo4j_user': self.neo4j_user, |
| 55 | 'neo4j_password': self.neo4j_password, |
| 56 | 'neo4j_database': self.neo4j_database, |
| 57 | 'milvus_host': self.milvus_host, |
| 58 | 'milvus_port': self.milvus_port, |
| 59 | 'milvus_collection_name': self.milvus_collection_name, |
| 60 | 'milvus_dimension': self.milvus_dimension, |
| 61 | 'embedding_model': self.embedding_model, |
| 62 | 'llm_model': self.llm_model, |
| 63 | 'top_k': self.top_k, |
| 64 | |
| 65 | 'temperature': self.temperature, |
| 66 | 'max_tokens': self.max_tokens, |