/** * Schema 增强工具 * 提供隐式关系推断、关系类型细化等功能 * 用于提升 LLM 对数据库结构的理解,提高 Text2SQL 准确性 */ import type { TableInfo, RelationshipInfo } from '../types/adapter.js'; /** * Schema 增强配置 */ export interface SchemaEnhancerConfig { /** 是否启用隐式关系推断,默认 true */ enableInferredRelationships: boolean; /** 是否启用关系类型细化,默认 true */ enableRelationshipTypeRefinement: boolean; /** 推断关系的最小置信度阈值,低于此值的推断将被过滤,默认 0.7 */ minConfidenceThreshold: number; } /** * Schema 增强器类 */ export declare class SchemaEnhancer { private config; constructor(config?: Partial); /** * 增强关系信息 * 1. 为现有外键关系添加 source='foreign_key' 标记 * 2. 推断隐式关系并添加 source='inferred' 标记 * 3. 细化关系类型(区分 one-to-one 和 many-to-one) */ enhanceRelationships(tables: TableInfo[], existingRelationships: RelationshipInfo[]): RelationshipInfo[]; /** * 推断隐式关系 * 基于列命名规则推断表间关系,支持以下模式: * - xxx_id → xxxs.id 或 xxx.id * - xxxId → xxxs.id 或 xxx.id (驼峰命名) * - xxx_code → xxxs.code 或 xxx.code */ private inferRelationships; /** * 尝试为单个列推断关系 */ private tryInferRelation; /** * 查找目标表 */ private findTargetTable; /** * 细化关系类型 * 通过检查外键列是否有唯一约束来区分 one-to-one 和 many-to-one */ private refineRelationshipTypes; /** * 检查列是否有唯一约束 */ private hasUniqueConstraint; /** * 更新配置 */ updateConfig(config: Partial): void; /** * 获取当前配置 */ getConfig(): SchemaEnhancerConfig; } /** * 创建默认的 Schema 增强器实例 */ export declare function createSchemaEnhancer(config?: Partial): SchemaEnhancer; //# sourceMappingURL=schema-enhancer.d.ts.map