Download tests/test_retrieval.py from nvikou/corrective-rag-data-assistant: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/nvikou/corrective-rag-data-assistant/resolve/main/tests/test_retrieval.py
- Command line
-
hf download hf://spaces/nvikou/corrective-rag-data-assistant/tests/test_retrieval.py
-
curl -L -o test_retrieval.py https://huggingface.co/spaces/nvikou/corrective-rag-data-assistant/resolve/main/tests/test_retrieval.py
1.49 kB
| import os | |
| os.environ.setdefault("LLM_PROVIDER", "mock") | |
| os.environ.setdefault("EMBEDDING_BACKEND", "tfidf") | |
| from app.core.config import get_settings # noqa: E402 | |
| from app.crag.retriever import ( # noqa: E402 | |
| infer_sql_query, | |
| looks_numeric_question, | |
| retrieve_internal_docs, | |
| ) | |
| from app.ingestion.indexer import get_indexer, reset_indexer # noqa: E402 | |
| get_settings.cache_clear() | |
| reset_indexer() | |
| def test_indexer_loads_documents(): | |
| indexer = get_indexer() | |
| assert len(indexer.documents) >= 6 | |
| assert len(indexer.chunks) > 0 | |
| doc_ids = {d.doc_id for d in indexer.documents} | |
| assert "refund_policy" in doc_ids | |
| assert "sales_q1_2026" in doc_ids | |
| def test_retrieval_returns_relevant_refund_policy(): | |
| results = retrieve_internal_docs( | |
| "Quel est le délai de remboursement ?", top_k=3 | |
| ) | |
| assert results | |
| doc_ids = [r["doc_id"] for r in results] | |
| assert "refund_policy" in doc_ids | |
| def test_numeric_question_detection(): | |
| assert looks_numeric_question( | |
| "Quel client a le meilleur chiffre d'affaires en juin ?" | |
| ) | |
| assert not looks_numeric_question( | |
| "Quelle est la politique de remboursement ?" | |
| ) | |
| def test_infer_sql_query_extracts_month_and_product(): | |
| params = infer_sql_query( | |
| "Quel est le chiffre d'affaires total du Produit X en avril ?" | |
| ) | |
| assert params is not None | |
| assert params["filters"].get("mois") == "Avril" | |
| assert params["filters"].get("produit") == "Produit X" | |