Spaces:
Running
Running
embed_query: repo_type param picks the matching query prefix
Browse files
app.py
CHANGED
|
@@ -585,10 +585,21 @@ async def embeddings_batch(req: EmbBatchReq):
|
|
| 585 |
|
| 586 |
|
| 587 |
@app.get("/embed_query")
|
| 588 |
-
@cache(ttl=CACHE_TTL, key="embq:{text}")
|
| 589 |
-
async def embed_query_route(
|
| 590 |
-
|
| 591 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
|
| 593 |
|
| 594 |
class VectorSearchReq(BaseModel):
|
|
|
|
| 585 |
|
| 586 |
|
| 587 |
@app.get("/embed_query")
|
| 588 |
+
@cache(ttl=CACHE_TTL, key="embq:{repo_type}:{text}")
|
| 589 |
+
async def embed_query_route(
|
| 590 |
+
text: str = Query(min_length=3, max_length=200),
|
| 591 |
+
repo_type: str = Query(default="datasets"),
|
| 592 |
+
):
|
| 593 |
+
"""Embed a free-text topic phrase with the serving query encoder.
|
| 594 |
+
|
| 595 |
+
repo_type picks the query prefix the corpus was embedded against
|
| 596 |
+
(datasets use the instruct prompt, models the search_query prefix).
|
| 597 |
+
"""
|
| 598 |
+
if repo_type not in ("datasets", "models"):
|
| 599 |
+
raise HTTPException(status_code=422, detail="repo_type must be datasets|models")
|
| 600 |
+
prompt = (f"Instruct: {DS_TASK}\nQuery:{text}" if repo_type == "datasets"
|
| 601 |
+
else f"search_query: {text}")
|
| 602 |
+
return {"embedding": embed_query(prompt)}
|
| 603 |
|
| 604 |
|
| 605 |
class VectorSearchReq(BaseModel):
|