Spaces:
Sleeping
Sleeping
File size: 2,090 Bytes
ef904b0 | 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #!/usr/bin/env python3
"""
FedInsight - Simple Query Script (retrieval only)
Embeds your question and prints the most relevant FOMC chunks from the vector
store. No LLM involved - this is pure semantic search, useful for sanity checks.
Usage:
python scripts/query.py "What did the Fed say about inflation in 2023?"
python scripts/query.py "labor market" --k 10
python scripts/query.py "rate decision" --backend chroma
"""
import argparse
import sys
from pathlib import Path
from loguru import logger
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from src.rag.retriever import Retriever
def main():
parser = argparse.ArgumentParser(description="FedInsight semantic search")
parser.add_argument("query", type=str, help="Your search query (in quotes)")
parser.add_argument("--k", type=int, default=5, help="Number of results (default: 5)")
parser.add_argument("--backend", type=str, default=None,
choices=["chroma", "pgvector"],
help="Vector store backend (default: VECTOR_BACKEND env var)")
parser.add_argument("--full", action="store_true",
help="Print full chunk text instead of a truncated preview")
args = parser.parse_args()
retriever = Retriever(backend=args.backend)
results = retriever.search(args.query, k=args.k)
if not results:
logger.warning("No results. Have you run the ingestion step?")
return
print(f"\nTop {len(results)} results for: {args.query!r}\n" + "=" * 70)
for i, r in enumerate(results, start=1):
meta = r.get("metadata", {})
date = meta.get("meeting_date", "unknown date")
score = r.get("score", 0.0)
content = r.get("content", "").strip()
if not args.full and len(content) > 400:
content = content[:400].rstrip() + "..."
print(f"\n[{i}] score={score:.3f} | {date}")
print("-" * 70)
print(content)
print()
if __name__ == "__main__":
main()
|