feat(matching): rank with semantic embeddings and explain matches by evidence
This commit is contained in:
1 parent
facc1789b1
commit
24b64d698a
215 files changed
+16951
-327
No files matched your search
@@ -12,6 +12,223 @@ func (s *ProblemStatusCode) Error() string {
|
||||
return fmt.Sprintf("code %d: %+v", s.StatusCode, s.Response)
|
||||
}
|
||||
|
||||
type CreateMLEmbeddingsBadRequest ProblemStatusCode
|
||||
|
||||
func (*CreateMLEmbeddingsBadRequest) createMLEmbeddingsRes() {}
|
||||
|
||||
type CreateMLEmbeddingsRequestEntityTooLarge ProblemStatusCode
|
||||
|
||||
func (*CreateMLEmbeddingsRequestEntityTooLarge) createMLEmbeddingsRes() {}
|
||||
|
||||
type CreateMLEmbeddingsServiceUnavailable ProblemStatusCode
|
||||
|
||||
func (*CreateMLEmbeddingsServiceUnavailable) createMLEmbeddingsRes() {}
|
||||
|
||||
// Side of the retrieval pair that the texts belong to. The service owns the prompt of each side, so
|
||||
// callers never send model instructions.
|
||||
//
|
||||
// - query: the side that searches, such as a hiring need or one requirement of it. The service
|
||||
// prepends the retrieval instruction of the model.
|
||||
// - document: the side that is searched, such as a candidate card or one item of it. The service adds
|
||||
// no prompt.
|
||||
//
|
||||
// Ref: #/components/schemas/EmbeddingInputKind
|
||||
type EmbeddingInputKind string
|
||||
|
||||
const (
|
||||
EmbeddingInputKindQuery EmbeddingInputKind = "query"
|
||||
EmbeddingInputKindDocument EmbeddingInputKind = "document"
|
||||
)
|
||||
|
||||
// AllValues returns all EmbeddingInputKind values.
|
||||
func (EmbeddingInputKind) AllValues() []EmbeddingInputKind {
|
||||
return []EmbeddingInputKind{
|
||||
EmbeddingInputKindQuery,
|
||||
EmbeddingInputKindDocument,
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (s EmbeddingInputKind) MarshalText() ([]byte, error) {
|
||||
switch s {
|
||||
case EmbeddingInputKindQuery:
|
||||
return []byte(s), nil
|
||||
case EmbeddingInputKindDocument:
|
||||
return []byte(s), nil
|
||||
default:
|
||||
return nil, errors.Errorf("invalid value: %q", s)
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (s *EmbeddingInputKind) UnmarshalText(data []byte) error {
|
||||
switch EmbeddingInputKind(data) {
|
||||
case EmbeddingInputKindQuery:
|
||||
*s = EmbeddingInputKindQuery
|
||||
return nil
|
||||
case EmbeddingInputKindDocument:
|
||||
*s = EmbeddingInputKindDocument
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("invalid value: %q", data)
|
||||
}
|
||||
}
|
||||
|
||||
// The model that produced the vectors. A caller stores these values with every vector and never
|
||||
// compares vectors of different models, revisions, or prompt versions.
|
||||
// Ref: #/components/schemas/EmbeddingModel
|
||||
type EmbeddingModel struct {
|
||||
// Model repository identifier, for example ai-sage/Giga-Embeddings-instruct-480M-0826.
|
||||
ID string `json:"id"`
|
||||
// Pinned revision of the weights, a commit hash for a published model.
|
||||
Revision string `json:"revision"`
|
||||
// Length of every vector.
|
||||
Dimension int32 `json:"dimension"`
|
||||
// Token limit after which a text is truncated.
|
||||
MaxTokens int32 `json:"max_tokens"`
|
||||
// Version of the prompt and pooling recipe of the service. A change of the query instruction or the
|
||||
// pooling changes it.
|
||||
PromptVersion string `json:"prompt_version"`
|
||||
}
|
||||
|
||||
// GetID returns the value of ID.
|
||||
func (s *EmbeddingModel) GetID() string {
|
||||
return s.ID
|
||||
}
|
||||
|
||||
// GetRevision returns the value of Revision.
|
||||
func (s *EmbeddingModel) GetRevision() string {
|
||||
return s.Revision
|
||||
}
|
||||
|
||||
// GetDimension returns the value of Dimension.
|
||||
func (s *EmbeddingModel) GetDimension() int32 {
|
||||
return s.Dimension
|
||||
}
|
||||
|
||||
// GetMaxTokens returns the value of MaxTokens.
|
||||
func (s *EmbeddingModel) GetMaxTokens() int32 {
|
||||
return s.MaxTokens
|
||||
}
|
||||
|
||||
// GetPromptVersion returns the value of PromptVersion.
|
||||
func (s *EmbeddingModel) GetPromptVersion() string {
|
||||
return s.PromptVersion
|
||||
}
|
||||
|
||||
// SetID sets the value of ID.
|
||||
func (s *EmbeddingModel) SetID(val string) {
|
||||
s.ID = val
|
||||
}
|
||||
|
||||
// SetRevision sets the value of Revision.
|
||||
func (s *EmbeddingModel) SetRevision(val string) {
|
||||
s.Revision = val
|
||||
}
|
||||
|
||||
// SetDimension sets the value of Dimension.
|
||||
func (s *EmbeddingModel) SetDimension(val int32) {
|
||||
s.Dimension = val
|
||||
}
|
||||
|
||||
// SetMaxTokens sets the value of MaxTokens.
|
||||
func (s *EmbeddingModel) SetMaxTokens(val int32) {
|
||||
s.MaxTokens = val
|
||||
}
|
||||
|
||||
// SetPromptVersion sets the value of PromptVersion.
|
||||
func (s *EmbeddingModel) SetPromptVersion(val string) {
|
||||
s.PromptVersion = val
|
||||
}
|
||||
|
||||
// Texts to encode in one call. The service encodes them in a fixed, deterministic way: texts are
|
||||
// ordered by length with the request position as the tie-breaker, encoded in micro-batches of the
|
||||
// configured size, and returned in request order. The same texts in the same request on the same image
|
||||
// and thread count give the same vectors.
|
||||
// Ref: #/components/schemas/EmbeddingRequest
|
||||
type EmbeddingRequest struct {
|
||||
// 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`.
|
||||
Model OptString `json:"model"`
|
||||
Kind EmbeddingInputKind `json:"kind"`
|
||||
Texts []EmbeddingText `json:"texts"`
|
||||
}
|
||||
|
||||
// GetModel returns the value of Model.
|
||||
func (s *EmbeddingRequest) GetModel() OptString {
|
||||
return s.Model
|
||||
}
|
||||
|
||||
// GetKind returns the value of Kind.
|
||||
func (s *EmbeddingRequest) GetKind() EmbeddingInputKind {
|
||||
return s.Kind
|
||||
}
|
||||
|
||||
// GetTexts returns the value of Texts.
|
||||
func (s *EmbeddingRequest) GetTexts() []EmbeddingText {
|
||||
return s.Texts
|
||||
}
|
||||
|
||||
// SetModel sets the value of Model.
|
||||
func (s *EmbeddingRequest) SetModel(val OptString) {
|
||||
s.Model = val
|
||||
}
|
||||
|
||||
// SetKind sets the value of Kind.
|
||||
func (s *EmbeddingRequest) SetKind(val EmbeddingInputKind) {
|
||||
s.Kind = val
|
||||
}
|
||||
|
||||
// SetTexts sets the value of Texts.
|
||||
func (s *EmbeddingRequest) SetTexts(val []EmbeddingText) {
|
||||
s.Texts = val
|
||||
}
|
||||
|
||||
// Vectors in the order of the request texts.
|
||||
// Ref: #/components/schemas/EmbeddingResponse
|
||||
type EmbeddingResponse struct {
|
||||
Model EmbeddingModel `json:"model"`
|
||||
Kind EmbeddingInputKind `json:"kind"`
|
||||
Vectors []EmbeddingVector `json:"vectors"`
|
||||
}
|
||||
|
||||
// GetModel returns the value of Model.
|
||||
func (s *EmbeddingResponse) GetModel() EmbeddingModel {
|
||||
return s.Model
|
||||
}
|
||||
|
||||
// GetKind returns the value of Kind.
|
||||
func (s *EmbeddingResponse) GetKind() EmbeddingInputKind {
|
||||
return s.Kind
|
||||
}
|
||||
|
||||
// GetVectors returns the value of Vectors.
|
||||
func (s *EmbeddingResponse) GetVectors() []EmbeddingVector {
|
||||
return s.Vectors
|
||||
}
|
||||
|
||||
// SetModel sets the value of Model.
|
||||
func (s *EmbeddingResponse) SetModel(val EmbeddingModel) {
|
||||
s.Model = val
|
||||
}
|
||||
|
||||
// SetKind sets the value of Kind.
|
||||
func (s *EmbeddingResponse) SetKind(val EmbeddingInputKind) {
|
||||
s.Kind = val
|
||||
}
|
||||
|
||||
// SetVectors sets the value of Vectors.
|
||||
func (s *EmbeddingResponse) SetVectors(val []EmbeddingVector) {
|
||||
s.Vectors = val
|
||||
}
|
||||
|
||||
func (*EmbeddingResponse) createMLEmbeddingsRes() {}
|
||||
|
||||
type EmbeddingText string
|
||||
|
||||
type EmbeddingVector []float32
|
||||
|
||||
type GetMLReadyzOK MLReadinessResponse
|
||||
|
||||
func (*GetMLReadyzOK) getMLReadyzRes() {}
|
||||
@@ -297,6 +514,8 @@ func (s *Problem) SetErrors(val []ProblemFieldError) {
|
||||
// - rate_limited (429): too many requests; see Retry-After.
|
||||
// - internal (500): unexpected server error.
|
||||
// - not_implemented (501): the operation is in the contract but not implemented yet.
|
||||
// - service_unavailable (503): the service cannot serve the request now, for example while a model
|
||||
// loads; retry later.
|
||||
//
|
||||
// The 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
|
||||
@@ -325,6 +544,7 @@ const (
|
||||
ProblemCodeRateLimited ProblemCode = "rate_limited"
|
||||
ProblemCodeInternal ProblemCode = "internal"
|
||||
ProblemCodeNotImplemented ProblemCode = "not_implemented"
|
||||
ProblemCodeServiceUnavailable ProblemCode = "service_unavailable"
|
||||
)
|
||||
|
||||
// AllValues returns all ProblemCode values.
|
||||
@@ -350,6 +570,7 @@ func (ProblemCode) AllValues() []ProblemCode {
|
||||
ProblemCodeRateLimited,
|
||||
ProblemCodeInternal,
|
||||
ProblemCodeNotImplemented,
|
||||
ProblemCodeServiceUnavailable,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,6 +617,8 @@ func (s ProblemCode) MarshalText() ([]byte, error) {
|
||||
return []byte(s), nil
|
||||
case ProblemCodeNotImplemented:
|
||||
return []byte(s), nil
|
||||
case ProblemCodeServiceUnavailable:
|
||||
return []byte(s), nil
|
||||
default:
|
||||
return nil, errors.Errorf("invalid value: %q", s)
|
||||
}
|
||||
@@ -464,6 +687,9 @@ func (s *ProblemCode) UnmarshalText(data []byte) error {
|
||||
case ProblemCodeNotImplemented:
|
||||
*s = ProblemCodeNotImplemented
|
||||
return nil
|
||||
case ProblemCodeServiceUnavailable:
|
||||
*s = ProblemCodeServiceUnavailable
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("invalid value: %q", data)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user