Spaces:
Sleeping
Sleeping
Upload 3 files
Browse filesFiles changed (3)
- .env.exampleAdded+25
- config.py+2-1
- embeddings.py+23-1
12345678910111213141516171819202122232425# Configuration de l'API FAQ
# Copier ce fichier en .env et remplir les valeurs
# Modèle d'embedding à utiliser
# Options: "intfloat/multilingual-e5-small" (par défaut), "intfloat/multilingual-e5-base", etc.
MODEL_NAME=intfloat/multilingual-e5-small
# Nom de la collection ChromaDB utilisée pour l'indexation
CHROMA_COLLECTION_NAME=faq
# Seuil de confiance pour retourner une réponse (0.0 à 1.0)
# 0.5 par défaut - à augmenter pour être plus strict, réduire pour être plus permissif
SIMILARITY_THRESHOLD=0.5
# Nombre maximum de candidats distincts à considérer
TOP_K=3
# Modèle Cross-Encoder utilisé pour le reranking
CROSS_ENCODER_MODEL_NAME=cross-encoder/ms-marco-MiniLM-L6-v2
# Seuil de différence relative entre le meilleur et le deuxième candidat
CROSS_ENCODER_THRESHOLD=0.20
# Seuil minimum du score Cross-Encoder pour conserver un seul candidat
CROSS_ENCODER_SINGLE_CANDIDATE_THRESHOLD=0.8019 unmodified lines2021222319 unmodified linesTOP_K = 3CROSS_ENCODER_MODEL_NAME = "cross-encoder/ms-marco-MiniLM-L6-v2"CROSS_ENCODER_THRESHOLD: float = float(os.getenv("CROSS_ENCODER_THRESHOLD", "0.20"))19 unmodified lines202122232419 unmodified linesTOP_K = 3CROSS_ENCODER_MODEL_NAME = "cross-encoder/ms-marco-MiniLM-L6-v2"CROSS_ENCODER_THRESHOLD: float = float(os.getenv("CROSS_ENCODER_THRESHOLD", "0.20"))CROSS_ENCODER_SINGLE_CANDIDATE_THRESHOLD: float = float(os.getenv("CROSS_ENCODER_SINGLE_CANDIDATE_THRESHOLD", "0.80"))
24 unmodified lines25262728293031242 unmodified lines27427527627727827924 unmodified linesfrom scipy.special import expitfrom config import (CHROMA_COLLECTION_NAME, MODEL_NAME, SIMILARITY_THRESHOLD,TOP_K, CROSS_ENCODER_MODEL_NAME, CROSS_ENCODER_THRESHOLD)from faq_loader import FAQEntry242 unmodified linesbest_candidate = ranked_candidates[0]second_candidate = ranked_candidates[1] if len(ranked_candidates) > 1 else Nonebest_score = best_candidate.cross_encoder_score or 0.0relative_gap = abs((best_score - second_candidate.cross_encoder_score) / best_score) \if second_candidate and best_score != 0 else 024 unmodified lines2526272829303132242 unmodified lines27527627727827928028128228328428528628728828929029129229329429529629729829930030124 unmodified linesfrom scipy.special import expitfrom config import (CHROMA_COLLECTION_NAME, MODEL_NAME, SIMILARITY_THRESHOLD,TOP_K, CROSS_ENCODER_MODEL_NAME, CROSS_ENCODER_THRESHOLD,CROSS_ENCODER_SINGLE_CANDIDATE_THRESHOLD,)from faq_loader import FAQEntry242 unmodified linesbest_candidate = ranked_candidates[0]second_candidate = ranked_candidates[1] if len(ranked_candidates) > 1 else Noneif len(ranked_candidates) == 1:if (best_candidate.cross_encoder_score is not Noneand best_candidate.cross_encoder_score > CROSS_ENCODER_SINGLE_CANDIDATE_THRESHOLD):logger.info("Un seul candidat disponible et score cross-encoder suffisant : "f"{best_candidate.cross_encoder_score:.3f}")return AnswerOutput(question=question,formulation=best_candidate.formulation,answer=best_candidate.response,theme=best_candidate.theme,similarity_score=round(best_candidate.similarity_score or 0.0, 4),cross_encoder_score=round(best_candidate.cross_encoder_score or 0.0, 4),list_candidates=candidates,confidence=True,)second_candidate = Nonebest_score = best_candidate.cross_encoder_score or 0.0relative_gap = abs((best_score - second_candidate.cross_encoder_score) / best_score) \if second_candidate and best_score != 0 else 0
.env.exampleAdded+25
config.py+2-1
embeddings.py+23-1