Spaces:
Paused
Paused
File size: 1,187 Bytes
b7980f7 5eb4857 b7980f7 5eb4857 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | from sqlalchemy import Column, String, Text, ForeignKey, Integer, Index
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from pgvector.sqlalchemy import Vector
from core.database import Base
from core.config import get_settings
from models.base import PrimaryKeyMixin, TimestampMixin
settings = get_settings()
class KBArticleChunk(Base, PrimaryKeyMixin, TimestampMixin):
__tablename__ = "kb_article_chunks"
article_id = Column(UUID(as_uuid=True), ForeignKey("kb_articles.id", ondelete="CASCADE"), nullable=False, index=True)
content = Column(Text, nullable=False)
chunk_index = Column(Integer, nullable=False)
# Vector embedding for semantic search at the chunk level
embedding = Column(Vector(settings.AI_EMBEDDING_DIM), nullable=True)
__table_args__ = (
Index(
'idx_kb_chunk_embedding_hnsw',
"embedding",
postgresql_using='hnsw',
postgresql_with={'m': 16, 'ef_construction': 64},
postgresql_ops={'embedding': 'vector_cosine_ops'}
),
)
# Relationships
article = relationship("KBArticle", back_populates="chunks")
|