Spaces:
Paused
Paused
Download models/kb_article_chunk.py from 3SCError404/miracle: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/3SCError404/miracle/resolve/main/models/kb_article_chunk.py
- Command line
-
hf download hf://spaces/3SCError404/miracle/models/kb_article_chunk.py
-
curl -L -o kb_article_chunk.py https://huggingface.co/spaces/3SCError404/miracle/resolve/main/models/kb_article_chunk.py
1.18 kB
| from sqlalchemy import Column, 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_TEXT_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") | |