qf46578 commited on
Commit
1aa4e22
·
verified ·
1 Parent(s): b645039

🦞 Add: backend/src/entities/knowledge-item.entity.ts

Browse files
backend/src/entities/knowledge-item.entity.ts ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn,
3
+ ManyToOne, JoinColumn, Index
4
+ } from 'typeorm';
5
+ import { KnowledgeBase } from './knowledge-base.entity';
6
+
7
+ export type KnowledgeItemStatus = 'active' | 'inactive' | 'pending_review' | 'archived';
8
+
9
+ @Entity('knowledge_items')
10
+ @Index(['knowledgeBaseId', 'isActive'])
11
+ @Index(['category'])
12
+ export class KnowledgeItem {
13
+ @PrimaryGeneratedColumn('uuid')
14
+ id: string;
15
+
16
+ @Column({ name: 'knowledge_base_id', type: 'uuid' })
17
+ knowledgeBaseId: string;
18
+
19
+ @ManyToOne(() => KnowledgeBase, kb => kb.items)
20
+ @JoinColumn({ name: 'knowledge_base_id' })
21
+ knowledgeBase: KnowledgeBase;
22
+
23
+ @Column({ type: 'text' })
24
+ question: string;
25
+
26
+ @Column({ type: 'text' })
27
+ answer: string;
28
+
29
+ @Column({ name: 'keywords', type: 'simple-array', nullable: true })
30
+ keywords: string[];
31
+
32
+ @Column({ type: 'vector', nullable: true, select: false })
33
+ embedding: string | null;
34
+
35
+ @Column({ length: 50, nullable: true })
36
+ category: string | null;
37
+
38
+ @Column({ type: 'simple-array', nullable: true })
39
+ tags: string[];
40
+
41
+ @Column({ type: 'text', nullable: true })
42
+ context: string | null; // 补充上下文信息
43
+
44
+ @Column({ name: 'usage_count', default: 0 })
45
+ usageCount: number;
46
+
47
+ @Column({ name: 'effectiveness_score', type: 'decimal', precision: 3, scale: 2, default: 0 })
48
+ effectivenessScore: number;
49
+
50
+ @Column({ name: 'last_used_at', type: 'timestamp', nullable: true })
51
+ lastUsedAt: Date | null;
52
+
53
+ @Column({
54
+ name: 'status',
55
+ type: 'enum',
56
+ enum: ['active', 'inactive', 'pending_review', 'archived'],
57
+ default: 'active'
58
+ })
59
+ status: KnowledgeItemStatus;
60
+
61
+ @Column({ name: 'is_active', default: true })
62
+ isActive: boolean;
63
+
64
+ @Column({ name: 'created_by', type: 'uuid', nullable: true })
65
+ createdBy: string | null;
66
+
67
+ @Column({ name: 'updated_by', type: 'uuid', nullable: true })
68
+ updatedBy: string | null;
69
+
70
+ @CreateDateColumn({ name: 'created_at' })
71
+ createdAt: Date;
72
+
73
+ @UpdateDateColumn({ name: 'updated_at' })
74
+ updatedAt: Date;
75
+ }