feat(knowledge-base): 增加全局知识库管理

This commit is contained in:
2026-06-08 21:37:32 +08:00
parent e6fa738fd5
commit 5ecf78c5d6
12 changed files with 1425 additions and 2 deletions

View File

@@ -399,6 +399,45 @@ class RegulatoryRuleVersion(models.Model):
return self.code
class KnowledgeBaseDocument(models.Model):
"""Stores user-managed knowledge-base source documents."""
class Status(models.TextChoices):
ACTIVE = "active", "启用"
DISABLED = "disabled", "停用"
DELETED = "deleted", "已删除"
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="knowledge_base_documents",
)
display_name = models.CharField(max_length=255)
original_name = models.CharField(max_length=255)
storage_path = models.CharField(max_length=500)
file_size = models.BigIntegerField(default=0)
content_type = models.CharField(max_length=120, blank=True, default="")
description = models.TextField(blank=True, default="")
status = models.CharField(max_length=20, choices=Status.choices, default=Status.ACTIVE)
is_active = models.BooleanField(default=True)
indexed_chunk_count = models.PositiveIntegerField(default=0)
metadata = models.JSONField(default=dict, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
db_table = "ra_knowledge_base_document"
ordering = ["-updated_at", "-id"]
indexes = [
models.Index(fields=["user", "status"], name="idx_ra_kb_doc_user_status"),
models.Index(fields=["user", "created_at"], name="idx_ra_kb_doc_user_created"),
models.Index(fields=["status", "updated_at"], name="idx_ra_kb_doc_status_updated"),
]
def __str__(self) -> str:
return self.display_name
class ApplicationFormFillBatch(models.Model):
"""Tracks one application-form auto-fill workflow run."""