from sqlalchemy import Integer, String, Text from sqlalchemy.dialects.sqlite import JSON from sqlalchemy.orm import Mapped, mapped_column from core_db import AuditMixin, Base, TenantMixin, VersionMixin from core_shared import JSONValue class KnowledgeChunk(TenantMixin, AuditMixin, VersionMixin, Base): __tablename__ = "knowledge_chunk" knowledge_base_id: Mapped[str] = mapped_column(String(36), index=True) document_id: Mapped[str] = mapped_column(String(36), index=True) chunk_index: Mapped[int] = mapped_column(Integer) content_text: Mapped[str] = mapped_column(Text) token_count: Mapped[int] = mapped_column(Integer, default=0) embedding_model: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True) embedding_json: Mapped[list[float] | None] = mapped_column(JSON, nullable=True) metadata_json: Mapped[dict[str, JSONValue] | None] = mapped_column(JSON, nullable=True)