knowledge_chunk.py 1009 B

1234567891011121314151617181920
  1. from sqlalchemy import Integer, String, Text
  2. from sqlalchemy.dialects.sqlite import JSON
  3. from sqlalchemy.orm import Mapped, mapped_column
  4. from core_db import AuditMixin, Base, TenantMixin, VersionMixin
  5. from core_shared import JSONValue
  6. class KnowledgeChunk(TenantMixin, AuditMixin, VersionMixin, Base):
  7. __tablename__ = "knowledge_chunk"
  8. knowledge_base_id: Mapped[str] = mapped_column(String(36), index=True)
  9. document_id: Mapped[str] = mapped_column(String(36), index=True)
  10. chunk_index: Mapped[int] = mapped_column(Integer)
  11. content_text: Mapped[str] = mapped_column(Text)
  12. token_count: Mapped[int] = mapped_column(Integer, default=0)
  13. embedding_model: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
  14. embedding_json: Mapped[list[float] | None] = mapped_column(JSON, nullable=True)
  15. embedding_vector: Mapped[str | None] = mapped_column(Text, nullable=True)
  16. metadata_json: Mapped[dict[str, JSONValue] | None] = mapped_column(JSON, nullable=True)