Sarisha Das commited on
Commit
bef14ab
Β·
1 Parent(s): 8628d72

fix import errors

Browse files
Files changed (2) hide show
  1. src/streamlit_app.py +0 -2
  2. utils/hybrid.py +1 -71
src/streamlit_app.py CHANGED
@@ -16,7 +16,6 @@ from utils.retrieval_helpers import enrich_search_results, enrich_bm25_search_re
16
  from utils.bm25 import load
17
  from utils.semantic import load_vector_store
18
  from utils.rag_pipeline import run_rag
19
- from utils.bm25 import load
20
  from utils.hybrid import HybridRetriever
21
 
22
  import markdown
@@ -36,7 +35,6 @@ st.set_page_config(
36
  )
37
 
38
  # ─── Paths ────────────────────────────────────────────────────────────────────
39
- ROOT = Path(__file__).resolve().parent.parent
40
  FEEDBACK_CSV = ROOT / "results" / "feedback.csv"
41
  FEEDBACK_CSV.parent.mkdir(parents=True, exist_ok=True)
42
 
 
16
  from utils.bm25 import load
17
  from utils.semantic import load_vector_store
18
  from utils.rag_pipeline import run_rag
 
19
  from utils.hybrid import HybridRetriever
20
 
21
  import markdown
 
35
  )
36
 
37
  # ─── Paths ────────────────────────────────────────────────────────────────────
 
38
  FEEDBACK_CSV = ROOT / "results" / "feedback.csv"
39
  FEEDBACK_CSV.parent.mkdir(parents=True, exist_ok=True)
40
 
utils/hybrid.py CHANGED
@@ -167,74 +167,4 @@ class HybridRetriever(BaseRetriever):
167
  "HybridRetriever: BM25=%d, Semantic=%d β†’ fused=%d (returning top %d)",
168
  len(bm25_docs), len(semantic_docs), len(rrf_scores), len(top_docs),
169
  )
170
- return top_docs
171
-
172
-
173
- # ---------------------------------------------------------------------------
174
- # Convenience loader
175
- # ---------------------------------------------------------------------------
176
-
177
- def load_hybrid_retriever(
178
- bm25_index_path: str = "data/processed/tokenisation/bm25_index_mini.pkl",
179
- faiss_store_path: str = "data/processed/embeddings",
180
- k: int = 5,
181
- bm25_weight: float = 0.5,
182
- semantic_weight: float = 0.5,
183
- rrf_c: int = 60,
184
- fetch_multiplier: int = 3,
185
- ) -> HybridRetriever:
186
- """
187
- Load both indexes from disk and return a ready-to-use HybridRetriever.
188
-
189
- Call this once in your notebook or app.py, then pass the result to run_rag().
190
-
191
- Parameters
192
- ----------
193
- bm25_index_path : Path to the pickled BM25Retriever (from bm25.build_and_save())
194
- faiss_store_path : Directory containing index.faiss + index.pkl
195
- (from semantic.build_and_save_vector_store())
196
- k : Number of documents to return per query
197
- bm25_weight : RRF weight for BM25 (keyword signal). Default 0.5.
198
- semantic_weight : RRF weight for semantic (meaning signal). Default 0.5.
199
- Weights don't need to sum to 1 but relative scale matters.
200
- rrf_c : RRF rank-dampening constant. Default 60 (standard).
201
- fetch_multiplier : Candidates to fetch per retriever = k * fetch_multiplier.
202
-
203
- Returns
204
- -------
205
- HybridRetriever
206
- A LangChain-compatible retriever pipeable with |.
207
-
208
- Example
209
- -------
210
- >>> from utils.hybrid import load_hybrid_retriever
211
- >>> from utils.rag_pipeline import run_rag
212
- >>>
213
- >>> hybrid = load_hybrid_retriever(k=5)
214
- >>> answer = run_rag(hybrid, "Best coffee beans for a French press")
215
- >>> print(answer)
216
- """
217
- # Import here to avoid circular imports when used from rag_pipeline.py
218
- from utils.bm25 import load as load_bm25
219
- from utils.semantic import load_vector_store
220
-
221
- print(f"Loading BM25 index from: {bm25_index_path}")
222
- bm25_ret: BM25Retriever = load_bm25(bm25_index_path)
223
-
224
- print(f"Loading FAISS store from: {faiss_store_path}")
225
- faiss_store: FAISS = load_vector_store(faiss_store_path)
226
-
227
- retriever = HybridRetriever(
228
- bm25_retriever=bm25_ret,
229
- semantic_store=faiss_store,
230
- k=k,
231
- bm25_weight=bm25_weight,
232
- semantic_weight=semantic_weight,
233
- rrf_c=rrf_c,
234
- fetch_multiplier=fetch_multiplier,
235
- )
236
- print(
237
- f"HybridRetriever ready β€” k={k}, "
238
- f"BM25 weight={bm25_weight}, Semantic weight={semantic_weight}, RRF c={rrf_c}"
239
- )
240
- return retriever
 
167
  "HybridRetriever: BM25=%d, Semantic=%d β†’ fused=%d (returning top %d)",
168
  len(bm25_docs), len(semantic_docs), len(rrf_scores), len(top_docs),
169
  )
170
+ return top_docs