feat: add chunk BM25 and reproducible RRF retrieval
This commit is contained in:
@@ -23,7 +23,7 @@ def test_real_local_model_vectors_retrieval_and_http_restart(migrated_database):
|
||||
"HF_HUB_DISABLE_IMPLICIT_TOKEN": "1",
|
||||
"TOKENIZERS_PARALLELISM": "false",
|
||||
}
|
||||
query = {"query": "合成测试中交通安排应查阅哪份资料?"}
|
||||
query = {"query": "合成测试中交通安排应查阅哪份资料?", "top_k": 3}
|
||||
with server(migrated_database, environment_overrides=options) as client:
|
||||
ids = []
|
||||
for topic, body in [
|
||||
@@ -75,6 +75,18 @@ def test_real_local_model_vectors_retrieval_and_http_restart(migrated_database):
|
||||
assert {h["knowledge_id"] for h in first["results"]} == set(ids)
|
||||
assert all(-1 <= h["score"] <= 1 for h in first["results"])
|
||||
assert first["config"]["space"]["spec"]["revision"] == SMALL_ZH.revision
|
||||
response = client.post(
|
||||
"/api/retrieval/hybrid", json={**query, "candidate_k": 3}, timeout=60
|
||||
)
|
||||
assert response.status_code == 200, response.text
|
||||
hybrid = response.json()
|
||||
assert hybrid["vector_version_id"] == version["id"]
|
||||
assert hybrid["text_index_version_id"] == text_["id"]
|
||||
assert hybrid["config"]["space"]["spec"]["revision"] == SMALL_ZH.revision
|
||||
assert {h["knowledge_id"] for h in hybrid["results"]} == set(ids)
|
||||
assert hybrid["vector_candidates"]
|
||||
keyword = client.post("/api/retrieval/chunks", json=query).json()
|
||||
assert keyword["mode"] == "keyword_chunks" and keyword["results"]
|
||||
with migrated_database.connect() as c:
|
||||
assert (
|
||||
c.scalar(
|
||||
@@ -89,3 +101,15 @@ def test_real_local_model_vectors_retrieval_and_http_restart(migrated_database):
|
||||
response = client.post("/api/retrieval/vector", json=query, timeout=60)
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json()["results"] == first["results"]
|
||||
for result, endpoint in [(hybrid, "hybrid"), (keyword, "chunks")]:
|
||||
assert client.get(f"/api/retrieval/runs/{result['run_id']}").json() == result
|
||||
response = client.post(
|
||||
f"/api/retrieval/{endpoint}",
|
||||
json={**query, **({"candidate_k": 3} if endpoint == "hybrid" else {})},
|
||||
timeout=60,
|
||||
)
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json()["results"] == result["results"]
|
||||
if endpoint == "hybrid":
|
||||
assert response.json()["lexical_candidates"] == result["lexical_candidates"]
|
||||
assert response.json()["vector_candidates"] == result["vector_candidates"]
|
||||
|
||||
Reference in New Issue
Block a user