30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
"""知识库分块向量模型。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Optional
|
|
|
|
from sqlalchemy import BigInteger, ForeignKey, Integer, Text, VARCHAR
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from .base import Base
|
|
from .types import JSONB, Vector
|
|
|
|
|
|
class KnowledgeBaseChunk(Base):
|
|
__tablename__ = "knowledge_base_chunks"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
doc_id: Mapped[Optional[int]] = mapped_column(
|
|
Integer,
|
|
ForeignKey("knowledge_base_docs.id", ondelete="CASCADE"),
|
|
nullable=True,
|
|
index=True,
|
|
)
|
|
source_type: Mapped[str] = mapped_column(VARCHAR(32), nullable=False, default="doc", index=True)
|
|
project_id: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True, index=True)
|
|
content: Mapped[str] = mapped_column(Text, nullable=False)
|
|
embedding: Mapped[Optional[Any]] = mapped_column(Vector(768), nullable=True)
|
|
chunk_index: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
|
chunk_metadata: Mapped[Optional[Any]] = mapped_column("metadata", JSONB, nullable=True)
|