salary-benchmark/app/services/cohere_client.py
DJP da3f5faa91 Initial commit: Salary Benchmark Tool
FastAPI + React + PostgreSQL salary benchmarking tool with AI research pipeline.
- Seed data for 25+ New York roles (junior/mid/senior levels)
- Single + bulk lookup with location alias mapping (NYC -> New York, etc.)
- Research pipeline: Serper -> Firecrawl -> Cohere Rerank -> Claude analysis
- Editable validation UI for AI-proposed benchmarks
- CSV export, Montserrat font, black/white/#FFC407 design
- Fully Dockerized (app + db + frontend)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 22:47:32 -04:00

27 lines
657 B
Python

import cohere
from app.config import settings
async def rerank_results(query: str, chunks: list[str]) -> dict:
if not chunks:
return {"top_chunks": []}
client = cohere.AsyncClientV2(api_key=settings.cohere_api_key)
response = await client.rerank(
model="rerank-v3.5",
query=query,
documents=chunks,
top_n=min(5, len(chunks)),
)
top_chunks = []
for result in response.results:
top_chunks.append(
{
"content": chunks[result.index],
"relevance_score": result.relevance_score,
}
)
return {"top_chunks": top_chunks}