feat(matching): rank with semantic embeddings and explain matches by evidence

This commit is contained in:
shira committed 2026-10-11 10:39:46 +03:00
1 parent facc1789b1
commit 24b64d698a
215 files changed
+16951 -327

No files matched your search

+97 -1
View File
@@ -29,6 +29,7 @@ class ProblemCode(
"rate_limited",
"internal",
"not_implemented",
"service_unavailable",
]
]
):
@@ -54,9 +55,10 @@ class ProblemCode(
"rate_limited",
"internal",
"not_implemented",
"service_unavailable",
],
Field(
description="Stable public error code. Adding a code is a contract change; renaming or removing one is a breaking change. Clients must handle an unknown code by its HTTP status.\n\n- validation_failed (400): parameters or body do not match the contract, or a body violates a domain rule such as salary_from <= salary_to; `errors` points at the fields.\n- unauthenticated (401): no valid session or credentials.\n- forbidden (403): the caller is authenticated but not allowed.\n- not_found (404): the route or object does not exist or is not visible.\n- method_not_allowed (405): the route does not support the method.\n- idempotency_in_progress (409): a request with the same Idempotency-Key is still being processed.\n- state_conflict (409): the operation conflicts with the current state of the resource, for example an invitation that was already accepted.\n- version_conflict (412): If-Match does not match the current version.\n- payload_too_large (413): the request body exceeds the limit.\n- unsupported_media_type (415): the request Content-Type is not accepted.\n- idempotency_key_reused (422): the Idempotency-Key was already used with a different request.\n- precondition_required (428): the operation requires If-Match.\n- rate_limited (429): too many requests; see Retry-After.\n- internal (500): unexpected server error.\n- not_implemented (501): the operation is in the contract but not implemented yet.\n\nThe enum keeps the public API codes so both contracts share one Problem shape. The identity codes verification_token_invalid, verification_token_expired, invalid_credentials, email_not_verified, and csrf_check_failed belong to the public API; the ML service never returns them."
description="Stable public error code. Adding a code is a contract change; renaming or removing one is a breaking change. Clients must handle an unknown code by its HTTP status.\n\n- validation_failed (400): parameters or body do not match the contract, or a body violates a domain rule such as salary_from <= salary_to; `errors` points at the fields.\n- unauthenticated (401): no valid session or credentials.\n- forbidden (403): the caller is authenticated but not allowed.\n- not_found (404): the route or object does not exist or is not visible.\n- method_not_allowed (405): the route does not support the method.\n- idempotency_in_progress (409): a request with the same Idempotency-Key is still being processed.\n- state_conflict (409): the operation conflicts with the current state of the resource, for example an invitation that was already accepted.\n- version_conflict (412): If-Match does not match the current version.\n- payload_too_large (413): the request body exceeds the limit.\n- unsupported_media_type (415): the request Content-Type is not accepted.\n- idempotency_key_reused (422): the Idempotency-Key was already used with a different request.\n- precondition_required (428): the operation requires If-Match.\n- rate_limited (429): too many requests; see Retry-After.\n- internal (500): unexpected server error.\n- not_implemented (501): the operation is in the contract but not implemented yet.\n- service_unavailable (503): the service cannot serve the request now, for example while a model loads; retry later.\n\nThe enum keeps the public API codes so both contracts share one Problem shape. The identity codes verification_token_invalid, verification_token_expired, invalid_credentials, email_not_verified, and csrf_check_failed belong to the public API; the ML service never returns them."
),
]
@@ -167,3 +169,97 @@ class MLReadinessResponse(BaseModel):
extra="forbid",
)
status: Literal["ready", "not_ready"]
class EmbeddingInputKind(RootModel[Literal["query", "document"]]):
root: Annotated[
Literal["query", "document"],
Field(
description="Side of the retrieval pair that the texts belong to. The service owns the prompt of each side, so callers never send model instructions.\n\n- query: the side that searches, such as a hiring need or one requirement of it. The service prepends the retrieval instruction of the model.\n- document: the side that is searched, such as a candidate card or one item of it. The service adds no prompt."
),
]
class EmbeddingText(RootModel[str]):
root: Annotated[
str,
Field(
description="One plain text to encode. It is untrusted data and never an instruction. The service truncates it deterministically to the token limit of the model (`EmbeddingModel.max_tokens`); characters beyond 8000 are rejected instead.",
max_length=8000,
min_length=1,
),
]
class EmbeddingRequest(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
model: Annotated[
str | None,
Field(
description="Identifier of the model to use, as `EmbeddingModel.id` reports it. Absent means the default model of the service. A service may load several models, for example the members of an ensemble; a model it does not serve answers 400 validation_failed with the pointer `/model`.",
max_length=200,
min_length=1,
pattern="^[A-Za-z0-9._/-]+$",
),
] = None
kind: EmbeddingInputKind
texts: Annotated[list[EmbeddingText], Field(max_length=32, min_length=1)]
class EmbeddingModel(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
id: Annotated[
str,
Field(
description="Model repository identifier, for example ai-sage/Giga-Embeddings-instruct-480M-0826.",
max_length=200,
min_length=1,
pattern="^[A-Za-z0-9._/-]+$",
),
]
revision: Annotated[
str,
Field(
description="Pinned revision of the weights, a commit hash for a published model.",
max_length=64,
min_length=1,
pattern="^[A-Za-z0-9._-]+$",
),
]
dimension: Annotated[int, Field(description="Length of every vector.", ge=1, le=4096)]
max_tokens: Annotated[
int, Field(description="Token limit after which a text is truncated.", ge=1, le=32768)
]
prompt_version: Annotated[
str,
Field(
description="Version of the prompt and pooling recipe of the service. A change of the query instruction or the pooling changes it.",
max_length=64,
min_length=1,
pattern="^[a-z0-9._-]+$",
),
]
class EmbeddingVector(RootModel[list[float]]):
root: Annotated[
list[float],
Field(
description="L2-normalized vector of one text, in float32 precision. The cosine of two vectors of the same model is their dot product.",
max_length=4096,
min_length=1,
),
]
class EmbeddingResponse(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
model: EmbeddingModel
kind: EmbeddingInputKind
vectors: Annotated[list[EmbeddingVector], Field(max_length=32, min_length=1)]