Spaces:
Sleeping
Sleeping
Download query_engine/models.py from tiramesu55/powerintel: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/tiramesu55/powerintel/resolve/main/query_engine/models.py
- Command line
-
hf download hf://spaces/tiramesu55/powerintel/query_engine/models.py
-
curl -L -o models.py https://huggingface.co/spaces/tiramesu55/powerintel/resolve/main/query_engine/models.py
1.13 kB
| """ | |
| models.py | |
| Pydantic models for the RAG query pipeline. | |
| """ | |
| from typing import List | |
| from pydantic import BaseModel | |
| class SearchResult(BaseModel): | |
| """A single chunk retrieved from Qdrant.""" | |
| chunk_id: str | |
| text: str | |
| source: str | |
| file_path: str | |
| score: float | |
| class RankedResult(BaseModel): | |
| """A chunk after Cohere reranking.""" | |
| chunk_id: str | |
| text: str | |
| source: str | |
| file_path: str | |
| rerank_score: float | |
| class QueryResponse(BaseModel): | |
| """Full response returned to the Gradio UI.""" | |
| answer: str | |
| sources: List[RankedResult] | |
| def format_for_gradio(self) -> str: | |
| """ | |
| Format as a single markdown string for Gradio ChatInterface. | |
| Answer followed by a deduplicated numbered source list. | |
| """ | |
| lines = [self.answer, "\n**Sources:**"] | |
| seen = set() | |
| for i, src in enumerate(self.sources, 1): | |
| if src.file_path in seen: | |
| continue | |
| seen.add(src.file_path) | |
| lines.append(f"{i}. `{src.source}` — {src.file_path}") | |
| return "\n".join(lines) | |