Spaces:
Running on Zero
Running on Zero
atakan
fix: Enforce parameter provenance, fix rendering/citations, add tools, harden agent loop
48ee375 | """Local document retrieval tool for ControlAI Agent.""" | |
| from __future__ import annotations | |
| from typing import Any | |
| from controlai_agent.registry import registry | |
| from controlai_rag.index import get_shared_index | |
| def search_control_references( | |
| query: str, | |
| top_k: int = 3, | |
| source_filter: str | None = None, | |
| ) -> dict[str, Any]: | |
| # Resolved per call (not at import) so newly uploaded documents are visible | |
| # immediately, without restarting the server. | |
| hits = get_shared_index().search(query=query, top_k=top_k, source_filter=source_filter) | |
| if not hits: | |
| return { | |
| "query": query, | |
| "results_found": 0, | |
| "message": "No matching reference passages found in local index.", | |
| } | |
| formatted_passages = [] | |
| for hit in hits: | |
| formatted_passages.append({ | |
| "citation": ( | |
| f"[{hit.get('source_name') or hit['filename']}" | |
| + (f", p. {hit['page']}]" if hit.get("page") else "]") | |
| ), | |
| "source_path": hit["source"], | |
| "relevance_score": hit["score"], | |
| "content": hit["text"][:600], | |
| }) | |
| return { | |
| "query": query, | |
| "results_found": len(formatted_passages), | |
| "passages": formatted_passages, | |
| } | |