Jayan12321 commited on
Commit
3baa772
·
verified ·
1 Parent(s): 21ef826

Upload folder using huggingface_hub

Browse files
config/__init__.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from config.settings import Settings, get_settings
2
+ from config.prompts import (
3
+ INSUFFICIENT_EVIDENCE,
4
+ SYSTEM_PROMPT,
5
+ REFUSAL_MESSAGE,
6
+ SYNTHETIC_QA_PROMPT,
7
+ )
8
+
9
+ __all__ = [
10
+ "Settings",
11
+ "get_settings",
12
+ "INSUFFICIENT_EVIDENCE",
13
+ "SYSTEM_PROMPT",
14
+ "REFUSAL_MESSAGE",
15
+ "SYNTHETIC_QA_PROMPT",
16
+ ]
config/__pycache__/__init__.cpython-314.pyc ADDED
Binary file (448 Bytes). View file
 
config/__pycache__/prompts.cpython-314.pyc ADDED
Binary file (1.28 kB). View file
 
config/__pycache__/settings.cpython-314.pyc ADDED
Binary file (4.76 kB). View file
 
config/prompts.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """System prompt and fallback messages for the RAG pipeline."""
2
+
3
+ SYSTEM_PROMPT = """You are a helpful knowledge assistant. Answer questions using ONLY the provided context.
4
+
5
+ Rules:
6
+ 1. Use only the provided context to answer. If the context is insufficient, say so.
7
+ 2. Cite your sources using [Source: title] format after each claim.
8
+ 3. Never invent facts, sources, or data that aren't in the context.
9
+ 4. Be concise and direct.
10
+
11
+ Context:
12
+ {context}
13
+
14
+ Question:
15
+ {question}
16
+
17
+ Answer using the context above, citing sources."""
18
+
19
+ INSUFFICIENT_EVIDENCE = (
20
+ "I don't have enough information in my knowledge base to answer this question. "
21
+ "Try uploading more documents or rephrasing your query."
22
+ )
23
+
24
+ REFUSAL_MESSAGE = (
25
+ "This query was blocked by the safety filter. "
26
+ "Please rephrase your question."
27
+ )
28
+
29
+ SYNTHETIC_QA_PROMPT = """Generate an evaluation question grounded in the supplied documents.
30
+
31
+ Return a JSON object with: id, question, answer, evidence_doc_ids, qtype.
32
+ evidence_doc_ids must come from the documents. Do not invent facts.
33
+
34
+ Question type: {qtype}
35
+ Documents:
36
+ {documents}
37
+ """
config/settings.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Configuration settings for the RAG engine.
2
+
3
+ Loads environment variables from .env or uses sensible defaults.
4
+ All settings can be customized via environment variables.
5
+ """
6
+
7
+ import os
8
+ from pathlib import Path
9
+ from dotenv import load_dotenv
10
+
11
+ ROOT = Path(__file__).resolve().parent.parent
12
+ load_dotenv(ROOT / ".env")
13
+
14
+
15
+ class Settings:
16
+ """Central configuration for paths, models, and retrieval hyperparameters."""
17
+
18
+ def __init__(self):
19
+ # LLM configuration
20
+ self.user_llm_api_key = os.getenv("USER_LLM_API_KEY", "").strip()
21
+ self.user_llm_base_url = os.getenv("USER_LLM_BASE_URL", "")
22
+ self.user_llm_model = os.getenv("USER_LLM_MODEL", "gpt-4o-mini")
23
+ self.llm_temperature = float(os.getenv("LLM_TEMPERATURE", "0.1"))
24
+ self.llm_max_tokens = int(os.getenv("LLM_MAX_TOKENS", "1000"))
25
+
26
+ # Embeddings & Vector Store
27
+ # HashEmbeddings = 100% offline, zero-dependency token hashing for demo/testing
28
+ self.use_hash_embeddings = os.getenv("USE_HASH_EMBEDDINGS", "true").lower() == "true"
29
+ self.embedding_model = os.getenv("EMBEDDING_MODEL", "all-MiniLM-L6-v2")
30
+ self.collection_name = "rag_engine_docs"
31
+
32
+ # Chunking parameters
33
+ self.chunk_size = int(os.getenv("CHUNK_SIZE", "400"))
34
+ self.chunk_overlap = int(os.getenv("CHUNK_OVERLAP", "50"))
35
+ self.parent_chunk_size = int(os.getenv("PARENT_CHUNK_SIZE", "1500"))
36
+
37
+ # Retrieval hyperparameters
38
+ self.dense_top_k = int(os.getenv("DENSE_TOP_K", "10"))
39
+ self.bm25_top_k = int(os.getenv("BM25_TOP_K", "10"))
40
+ self.final_top_k = int(os.getenv("FINAL_TOP_K", "4"))
41
+ self.dense_weight = float(os.getenv("DENSE_WEIGHT", "0.6"))
42
+ self.bm25_weight = float(os.getenv("BM25_WEIGHT", "0.4"))
43
+
44
+ # Storage paths
45
+ self.data_dir = ROOT / "data"
46
+ self.documents_file = self.data_dir / "documents.jsonl"
47
+ self.chroma_dir = self.data_dir / "chroma"
48
+ self.bm25_file = self.data_dir / "bm25_index.pkl"
49
+ self.parent_store_file = self.data_dir / "parents.jsonl"
50
+
51
+ # Ensure base directories exist
52
+ self.ensure_dirs()
53
+
54
+ def ensure_dirs(self):
55
+ """Create necessary data storage directories."""
56
+ self.data_dir.mkdir(parents=True, exist_ok=True)
57
+ self.chroma_dir.mkdir(parents=True, exist_ok=True)
58
+
59
+ def has_llm_key(self):
60
+ """Check if a valid LLM API key has been provided."""
61
+ return bool(self.user_llm_api_key) and self.user_llm_api_key != "your-api-key-here"
62
+
63
+
64
+ _cached_settings = None
65
+
66
+
67
+ def get_settings():
68
+ """Returns a singleton Settings instance."""
69
+ global _cached_settings
70
+ if _cached_settings is None:
71
+ _cached_settings = Settings()
72
+ return _cached_settings