Spaces:
Runtime error
Runtime error
BIM Query Deploy
Claude Opus 4.7 (1M context)
deploy: initial BIM Query API on Hugging Face Spaces
e6be672 Download app/models/query_result.py from 12mhsssss/bimquery-api: direct link, hf CLI and curl.
- Browser
- Download file 2.38 kB
-
https://huggingface.co/spaces/12mhsssss/bimquery-api/resolve/main/app/models/query_result.py
- Command line
-
hf download hf://spaces/12mhsssss/bimquery-api/app/models/query_result.py
-
curl -L -o query_result.py https://huggingface.co/spaces/12mhsssss/bimquery-api/resolve/main/app/models/query_result.py
2.38 kB
| # Copyright (C) 2026 Mattia Zatelli | |
| # | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU Affero General Public License as published by | |
| # the Free Software Foundation, either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU Affero General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU Affero General Public License | |
| # along with this program. If not, see <https://www.gnu.org/licenses/>. | |
| """Query result model""" | |
| from sqlalchemy import Column, Integer, String, Float, JSON, DateTime, ForeignKey, Index, text | |
| from sqlalchemy.orm import relationship | |
| from app.core.database import Base | |
| class QueryResult(Base): | |
| """Individual query result linking queries to elements""" | |
| __tablename__ = "query_results" | |
| # Primary key | |
| id = Column(Integer, primary_key=True, index=True) | |
| # Foreign keys | |
| query_id = Column(Integer, ForeignKey("queries.id", ondelete="CASCADE"), nullable=False) | |
| element_id = Column(Integer, ForeignKey("elements.id", ondelete="CASCADE"), nullable=False) | |
| # Result metadata | |
| relevance_score = Column(Float, nullable=True, doc="How relevant this element is to the query (0-1)") | |
| match_reason = Column(String(100), nullable=True, doc="Why this element matched (semantic, keyword, etc.)") | |
| result_data = Column(JSON, nullable=True, doc="Additional result-specific data") | |
| # Timestamps | |
| created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP")) | |
| # Relationships | |
| query = relationship("Query", back_populates="results", lazy="select") | |
| element = relationship("Element", back_populates="query_results", lazy="select") | |
| # Indexes | |
| __table_args__ = ( | |
| Index("idx_query_results_query_id", "query_id"), | |
| Index("idx_query_results_element_id", "element_id"), | |
| Index("idx_query_results_relevance_score", "relevance_score"), | |
| Index("idx_query_results_unique", "query_id", "element_id", unique=True), | |
| ) | |
| def __repr__(self): | |
| return f"<QueryResult(query_id={self.query_id}, element_id={self.element_id}, relevance={self.relevance_score})>" |