Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- app/pipeline.py +11 -2
- app/repository.py +10 -5
app/pipeline.py
CHANGED
|
@@ -70,8 +70,11 @@ def filter_phrases(filters: dict) -> list[str]:
|
|
| 70 |
|
| 71 |
# The registry sweep can fill the first several dozen ranks with trials, so the screen has to
|
| 72 |
# reach well past the displayed page or papers are cut before anyone judges them.
|
| 73 |
-
SCREEN_LIMIT =
|
| 74 |
SCREEN_BATCH = 40
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
|
| 77 |
def recount(studies: list[dict], sesoi: float, effect_type: str) -> dict:
|
|
@@ -355,10 +358,16 @@ class SearchPipeline:
|
|
| 355 |
}
|
| 356 |
for d in head
|
| 357 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
try:
|
| 359 |
batches = await asyncio.gather(
|
| 360 |
*(
|
| 361 |
-
|
| 362 |
for start in range(0, len(rows), SCREEN_BATCH)
|
| 363 |
)
|
| 364 |
)
|
|
|
|
| 70 |
|
| 71 |
# The registry sweep can fill the first several dozen ranks with trials, so the screen has to
|
| 72 |
# reach well past the displayed page or papers are cut before anyone judges them.
|
| 73 |
+
SCREEN_LIMIT = 500
|
| 74 |
SCREEN_BATCH = 40
|
| 75 |
+
# A full screen is 13 calls; an unbounded burst risks a rate limit, which fails open to
|
| 76 |
+
# unscreened results.
|
| 77 |
+
SCREEN_CONCURRENCY = 8
|
| 78 |
|
| 79 |
|
| 80 |
def recount(studies: list[dict], sesoi: float, effect_type: str) -> dict:
|
|
|
|
| 358 |
}
|
| 359 |
for d in head
|
| 360 |
]
|
| 361 |
+
slots = asyncio.Semaphore(SCREEN_CONCURRENCY)
|
| 362 |
+
|
| 363 |
+
async def screen_batch(batch: list[dict]) -> set[str]:
|
| 364 |
+
async with slots:
|
| 365 |
+
return await self.llm.screen(question, batch, usage)
|
| 366 |
+
|
| 367 |
try:
|
| 368 |
batches = await asyncio.gather(
|
| 369 |
*(
|
| 370 |
+
screen_batch(rows[start : start + SCREEN_BATCH])
|
| 371 |
for start in range(0, len(rows), SCREEN_BATCH)
|
| 372 |
)
|
| 373 |
)
|
app/repository.py
CHANGED
|
@@ -519,7 +519,12 @@ def authority_query(query: dict) -> dict:
|
|
| 519 |
}
|
| 520 |
|
| 521 |
|
| 522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 523 |
scores: dict[str, float] = {}
|
| 524 |
docs = {}
|
| 525 |
for ranking in rankings:
|
|
@@ -862,7 +867,7 @@ class ElasticRepository:
|
|
| 862 |
return {"documents": self.hits(result), "corpus": total["count"]}
|
| 863 |
|
| 864 |
async def retrieve(self, query: dict, vector: list[float] | None) -> tuple[list[dict], str]:
|
| 865 |
-
base = {"index": self.index, "size":
|
| 866 |
# Third ranking signal: citation authority over the same match set.
|
| 867 |
authority = authority_query(query)
|
| 868 |
if vector is None:
|
|
@@ -874,8 +879,8 @@ class ElasticRepository:
|
|
| 874 |
knn = {
|
| 875 |
"field": "embedding",
|
| 876 |
"query_vector": vector,
|
| 877 |
-
"k":
|
| 878 |
-
"num_candidates":
|
| 879 |
"filter": query,
|
| 880 |
}
|
| 881 |
try:
|
|
@@ -883,7 +888,7 @@ class ElasticRepository:
|
|
| 883 |
**base,
|
| 884 |
retriever={
|
| 885 |
"rrf": {
|
| 886 |
-
"rank_window_size":
|
| 887 |
"rank_constant": 60,
|
| 888 |
"retrievers": [
|
| 889 |
{"standard": {"query": query}},
|
|
|
|
| 519 |
}
|
| 520 |
|
| 521 |
|
| 522 |
+
# How many ranked records one search carries forward. It has to cover the relevance screen
|
| 523 |
+
# (pipeline.SCREEN_LIMIT): a shorter list would silently cap what can be screened.
|
| 524 |
+
RETRIEVE_LIMIT = 500
|
| 525 |
+
|
| 526 |
+
|
| 527 |
+
def rrf_fuse(*rankings: list[dict], limit: int = RETRIEVE_LIMIT) -> list[dict]:
|
| 528 |
scores: dict[str, float] = {}
|
| 529 |
docs = {}
|
| 530 |
for ranking in rankings:
|
|
|
|
| 867 |
return {"documents": self.hits(result), "corpus": total["count"]}
|
| 868 |
|
| 869 |
async def retrieve(self, query: dict, vector: list[float] | None) -> tuple[list[dict], str]:
|
| 870 |
+
base = {"index": self.index, "size": RETRIEVE_LIMIT, "source_excludes": ["embedding"]}
|
| 871 |
# Third ranking signal: citation authority over the same match set.
|
| 872 |
authority = authority_query(query)
|
| 873 |
if vector is None:
|
|
|
|
| 879 |
knn = {
|
| 880 |
"field": "embedding",
|
| 881 |
"query_vector": vector,
|
| 882 |
+
"k": RETRIEVE_LIMIT,
|
| 883 |
+
"num_candidates": 2 * RETRIEVE_LIMIT,
|
| 884 |
"filter": query,
|
| 885 |
}
|
| 886 |
try:
|
|
|
|
| 888 |
**base,
|
| 889 |
retriever={
|
| 890 |
"rrf": {
|
| 891 |
+
"rank_window_size": RETRIEVE_LIMIT,
|
| 892 |
"rank_constant": 60,
|
| 893 |
"retrievers": [
|
| 894 |
{"standard": {"query": query}},
|