feat(iit-manager): Integrate Dify knowledge base for hybrid retrieval
Completed features: - Created Dify dataset (Dify_test0102) with 2 processed documents - Linked test0102 project with Dify dataset ID - Extended intent detection to recognize query_protocol intent - Implemented queryDifyKnowledge method (semantic search Top 5) - Integrated hybrid retrieval (REDCap data + Dify documents) - Fixed AI hallucination bugs (intent detection + API field path) - Developed debugging scripts - Completed end-to-end testing (5 scenarios passed) - Generated comprehensive documentation (600+ lines) - Updated development plans and module status Technical highlights: - Single project single knowledge base architecture - Smart routing based on user intent - Prevent AI hallucination by injecting real data/documents - Session memory for multi-turn conversations - Reused LLMFactory for DeepSeek-V3 integration Bug fixes: - Fixed intent detection missing keywords - Fixed Dify API response field path error Testing: All scenarios verified in WeChat production environment Status: Fully tested and deployed
This commit is contained in:
105
backend/src/modules/iit-manager/check-iit-table-structure.ts
Normal file
105
backend/src/modules/iit-manager/check-iit-table-structure.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* 直接查询数据库中的iit_schema.projects表结构
|
||||
*/
|
||||
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function checkTableStructure() {
|
||||
try {
|
||||
console.log('🔍 查询 iit_schema.projects 表结构...\n');
|
||||
|
||||
// 1. 查询表的所有列信息
|
||||
const columns = await prisma.$queryRaw<any[]>`
|
||||
SELECT
|
||||
column_name,
|
||||
data_type,
|
||||
character_maximum_length,
|
||||
is_nullable,
|
||||
column_default
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'iit_schema'
|
||||
AND table_name = 'projects'
|
||||
ORDER BY ordinal_position
|
||||
`;
|
||||
|
||||
console.log('📋 表结构:');
|
||||
console.log('='.repeat(100));
|
||||
console.log(
|
||||
'Column Name'.padEnd(30) +
|
||||
'Data Type'.padEnd(20) +
|
||||
'Nullable'.padEnd(12) +
|
||||
'Default'
|
||||
);
|
||||
console.log('='.repeat(100));
|
||||
|
||||
columns.forEach(col => {
|
||||
const colName = col.column_name.padEnd(30);
|
||||
const dataType = (col.data_type +
|
||||
(col.character_maximum_length ? `(${col.character_maximum_length})` : '')
|
||||
).padEnd(20);
|
||||
const nullable = (col.is_nullable === 'YES' ? 'YES' : 'NO').padEnd(12);
|
||||
const defaultVal = col.column_default || '';
|
||||
|
||||
console.log(`${colName}${dataType}${nullable}${defaultVal}`);
|
||||
});
|
||||
|
||||
console.log('='.repeat(100));
|
||||
console.log(`\n总计: ${columns.length} 个字段\n`);
|
||||
|
||||
// 2. 检查是否存在 dify 相关字段
|
||||
const difyColumns = columns.filter(col =>
|
||||
col.column_name.toLowerCase().includes('dify')
|
||||
);
|
||||
|
||||
if (difyColumns.length > 0) {
|
||||
console.log('✅ 找到Dify相关字段:');
|
||||
difyColumns.forEach(col => {
|
||||
console.log(` - ${col.column_name} (${col.data_type}, nullable: ${col.is_nullable})`);
|
||||
});
|
||||
} else {
|
||||
console.log('❌ 未找到Dify相关字段');
|
||||
}
|
||||
console.log('');
|
||||
|
||||
// 3. 查询test0102项目的当前数据
|
||||
console.log('📊 查询test0102项目的当前配置...\n');
|
||||
const projects = await prisma.$queryRaw<any[]>`
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
redcap_project_id,
|
||||
redcap_url,
|
||||
dify_dataset_id,
|
||||
status,
|
||||
created_at
|
||||
FROM iit_schema.projects
|
||||
WHERE redcap_project_id = '16'
|
||||
`;
|
||||
|
||||
if (projects.length > 0) {
|
||||
console.log('✅ test0102项目信息:');
|
||||
const project = projects[0];
|
||||
console.log(` ID: ${project.id}`);
|
||||
console.log(` 名称: ${project.name}`);
|
||||
console.log(` REDCap项目ID: ${project.redcap_project_id}`);
|
||||
console.log(` REDCap URL: ${project.redcap_url}`);
|
||||
console.log(` Dify Dataset ID: ${project.dify_dataset_id || '(未设置)'}`);
|
||||
console.log(` 状态: ${project.status}`);
|
||||
console.log(` 创建时间: ${project.created_at}`);
|
||||
} else {
|
||||
console.log('❌ 未找到test0102项目');
|
||||
}
|
||||
|
||||
console.log('');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 查询失败:', error);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
checkTableStructure();
|
||||
|
||||
Reference in New Issue
Block a user