Skip to content

Commit f27dd69

Browse files
committed
add reranking test
1 parent f19554f commit f27dd69

File tree

2 files changed

+66
-23
lines changed

2 files changed

+66
-23
lines changed

examples/server/tests/features/rerank.feature

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,34 @@ Feature: llama.cpp server
99
And a model alias jina-reranker-v1-tiny-en
1010
And 42 as server seed
1111
And 2 slots
12-
And 128 as batch size
13-
And 128 as ubatch size
12+
And 512 as batch size
13+
And 512 as ubatch size
1414
And 512 KV cache size
1515
And embeddings extraction
1616
Then the server is starting
1717
Then the server is healthy
1818

19-
# TODO: implement some tests
20-
# https://github.com/ggerganov/llama.cpp/pull/9510
21-
# Scenario: Rerank
22-
# Given a prompt:
23-
# """
24-
# What is panda?
25-
# """
26-
# And a prompt:
27-
# """
28-
# Hi.
29-
# """
30-
# And a prompt:
31-
# """
32-
# It's a bear.
33-
# """
34-
# And a prompt:
35-
# """
36-
# The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.
37-
# """
38-
# When reranking request
39-
# Then reranking results are returned
19+
Scenario: Rerank
20+
Given a rerank query:
21+
"""
22+
Organic skincare products for sensitive skin
23+
"""
24+
And a rerank document:
25+
"""
26+
Organic skincare for sensitive skin with aloe vera and chamomile: Imagine the soothing embrace of nature with our organic skincare range, crafted specifically for sensitive skin. Infused with the calming properties of aloe vera and chamomile, each product provides gentle nourishment and protection. Say goodbye to irritation and hello to a glowing, healthy complexion.
27+
"""
28+
And a rerank document:
29+
"""
30+
New makeup trends focus on bold colors and innovative techniques: Step into the world of cutting-edge beauty with this seasons makeup trends. Bold, vibrant colors and groundbreaking techniques are redefining the art of makeup. From neon eyeliners to holographic highlighters, unleash your creativity and make a statement with every look.
31+
"""
32+
And a rerank document:
33+
"""
34+
Las nuevas tendencias de maquillaje se centran en colores vivos y técnicas innovadoras: Entra en el fascinante mundo del maquillaje con las tendencias más actuales. Colores vivos y técnicas innovadoras están revolucionando el arte del maquillaje. Desde delineadores neón hasta iluminadores holográficos, desata tu creatividad y destaca en cada look.
35+
"""
36+
And a rerank document:
37+
"""
38+
新的化妆趋势注重鲜艳的颜色和创新的技巧:进入化妆艺术的新纪元,本季的化妆趋势以大胆的颜色和创新的技巧为主。无论是霓虹眼线还是全息高光,每一款妆容都能让您脱颖而出,展现独特魅力。
39+
"""
40+
When reranking request
41+
Then reranking results are returned
42+
Then reranking highest score is index 2

examples/server/tests/features/steps/steps.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ def step_server_config(context, server_fqdn: str, server_port: str):
8383
context.concurrent_tasks = []
8484
context.prompts = []
8585

86+
context.reranking_query = None
87+
context.reranking_documents = []
88+
context.reranking_results = None
89+
8690

8791
@step('a model file {hf_file} from HF repo {hf_repo}')
8892
def step_download_hf_model(context, hf_file: str, hf_repo: str):
@@ -452,6 +456,14 @@ def step_impl(context, n_ga_w):
452456
def step_prompt_passkey(context):
453457
context.prompt_passkey = context_text(context)
454458

459+
@step('a rerank query')
460+
def step_set_rerank_query(context):
461+
context.reranking_query = context_text(context)
462+
context.reranking_documents = []
463+
464+
@step('a rerank document')
465+
def step_set_rerank_document(context):
466+
context.reranking_documents.append(context_text(context))
455467

456468
@step('{n_prompts:d} fixed prompts')
457469
def step_fixed_prompts(context, n_prompts):
@@ -619,6 +631,22 @@ async def step_compute_embedding(context):
619631
context.embeddings = await request_embedding(context_text(context), None, base_url=context.base_url)
620632

621633

634+
@step('reranking request')
635+
@async_run_until_complete
636+
async def step_compute_reranking(context):
637+
async with aiohttp.ClientSession(timeout=DEFAULT_TIMEOUT_SECONDS) as session:
638+
async with session.post(f'{context.base_url}/reranking',
639+
json={
640+
"query": context.reranking_query,
641+
"documents": context.reranking_documents,
642+
}) as response:
643+
if response.status == 200:
644+
response_json = await response.json()
645+
context.reranking_results = response_json['results']
646+
else:
647+
context.reranking_results = response.status
648+
649+
622650
@step('all embeddings are the same')
623651
@async_run_until_complete
624652
async def step_all_embeddings_are_the_same(context):
@@ -704,6 +732,18 @@ async def all_embeddings_are_generated(context):
704732
for i in range(n_embedding_requests):
705733
assert_embeddings(context.tasks_result.pop().pop())
706734

735+
@step('reranking results are returned')
736+
def reranking_results_are_returned(context):
737+
assert len(context.reranking_results) == len(context.reranking_documents)
738+
739+
@step('reranking highest score is index {idx:d}')
740+
def reranking_results_are_returned(context, idx: int):
741+
max_score, max_idx = 0, 0
742+
for res in context.reranking_results:
743+
if max_score < res['relevance_score']:
744+
max_score = res['relevance_score']
745+
max_idx = res['index']
746+
assert max_idx == idx
707747

708748
@step('adding special tokens')
709749
def step_tokenize_set_add_special(context):

0 commit comments

Comments
 (0)