knowledge_chunk.py 1008 B

12345678910111213141516171819
  1. from core_db import AuditMixin, Base, EntityMixin, VersionMixin
  2. from core_shared import JSONValue
  3. from sqlalchemy import Integer, String, Text
  4. from sqlalchemy.dialects.sqlite import JSON
  5. from sqlalchemy.orm import Mapped, mapped_column
  6. class KnowledgeChunk(EntityMixin, 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)