Skip to content

Commit 331a580

Browse files
committed
feat(search): gate Cohere reranking behind pro_user flag
- Add pro_user parameter to search methods - Only use Cohere reranking when pro_user=True - Free users get base V3 search (still good, just no Cohere) - Add reranking_used to logs for observability Cost control: Cohere charges per rerank call
1 parent b4d3d97 commit 331a580

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

backend/services/search_v3/integration.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ async def search(
156156
file_dependencies: Optional[Dict[str, List[str]]] = None,
157157
include_tests: bool = False,
158158
top_k: int = 10,
159-
use_reranking: bool = True
159+
use_reranking: bool = True,
160+
pro_user: bool = False
160161
) -> List[Dict]:
161162
"""
162163
Full Search V3 pipeline
164+
165+
Args:
166+
pro_user: Enable Cohere reranking (costs money, pro tier only)
163167
"""
164168
self._ensure_initialized()
165169

@@ -175,7 +179,8 @@ async def search(
175179
repo_id=repo_id,
176180
pinecone_index=pinecone_index,
177181
file_dependencies=file_dependencies,
178-
config=config
182+
config=config,
183+
pro_user=pro_user
179184
)
180185

181186

backend/services/search_v3/search_engine.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ async def search(
9595
repo_id: str,
9696
pinecone_index: Any,
9797
file_dependencies: Optional[Dict[str, List[str]]] = None,
98-
config: Optional[SearchConfig] = None
98+
config: Optional[SearchConfig] = None,
99+
pro_user: bool = False
99100
) -> List[Dict]:
100101
"""
101102
Execute full search pipeline
@@ -145,13 +146,15 @@ async def search(
145146
if not include_tests:
146147
results = self.code_graph_ranker.filter_test_files(results, include_tests)
147148

148-
# step 5: reranking
149-
if config.use_reranking and self.cohere_client and len(results) > 1:
149+
# step 5: reranking (pro users only - Cohere costs money)
150+
reranking_used = False
151+
if config.use_reranking and self.cohere_client and pro_user and len(results) > 1:
150152
results = await self._rerank_results(query, results, config.top_k * 2)
151153
# re-apply test filtering after rerank (Cohere doesn't know our preference)
152154
if not include_tests:
153155
results = [r for r in results if not self.code_graph_ranker._is_test_file(r.get('file_path', ''))]
154156
results = results[:config.top_k]
157+
reranking_used = True
155158
else:
156159
results = results[:config.top_k]
157160

@@ -161,7 +164,9 @@ async def search(
161164
query=query[:50],
162165
intent=analysis.intent.value,
163166
result_count=len(results),
164-
include_tests=include_tests)
167+
include_tests=include_tests,
168+
pro_user=pro_user,
169+
reranking_used=reranking_used)
165170

166171
return results
167172

0 commit comments

Comments
 (0)