Skip to content

Commit

Permalink
rename functions and use ranking
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasht86 committed Nov 15, 2024
1 parent 21ef303 commit 9cdc05a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions visual-retrieval-colpali/src/backend/vespa_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,14 @@ async def get_result_from_query(

rank_method = ranking.split("_")[0]
sim_map: bool = len(ranking.split("_")) > 1 and ranking.split("_")[1] == "sim"
if rank_method == "nn+colpali":
result = await self.query_vespa_nearest_neighbor(
query, q_embs, sim_map=sim_map
if rank_method == "colpali": # ColPali
result = await self.query_vespa_colpali(
query=query, ranking=rank_method, q_emb=q_embs, sim_map=sim_map
)
elif rank_method == "hybrid": # Hybrid ColPali+BM25
result = await self.query_vespa_colpali(
query=query, ranking=rank_method, q_emb=q_embs, sim_map=sim_map
)
elif rank_method == "bm25+colpali":
result = await self.query_vespa_default(query, q_embs, sim_map=sim_map)
elif rank_method == "bm25":
result = await self.query_vespa_bm25(query, q_embs, sim_map=sim_map)
else:
Expand Down Expand Up @@ -419,9 +421,10 @@ def get_rank_profile(self, ranking: str, sim_map: bool) -> str:
else:
return ranking

async def query_vespa_nearest_neighbor(
async def query_vespa_colpali(
self,
query: str,
ranking: str,
q_emb: torch.Tensor,
target_hits_per_query_tensor: int = 100,
hnsw_explore_additional_hits: int = 300,
Expand Down Expand Up @@ -467,7 +470,7 @@ async def query_vespa_nearest_neighbor(
f"select {self.get_fields(sim_map=sim_map)} from {self.VESPA_SCHEMA_NAME} where {nn_string} or userQuery()"
),
"ranking.profile": self.get_rank_profile(
"retrieval-and-rerank", sim_map
ranking=ranking, sim_map=sim_map
),
"timeout": timeout,
"hits": hits,
Expand Down

0 comments on commit 9cdc05a

Please sign in to comment.