AiEmbedding.h header
#include <ew/app/AiEmbedding.h>
Namespace ew::app
AiEmbeddingRequest struct
struct ew::app::AiEmbeddingRequest
A request to an embeddings model: the texts to embed and the model name. Provider-agnostic – any endpoint speaking the OpenAI-compatible embeddings shape (hosted or a local server) consumes it. The model name comes from settings, never hard-coded.
Members
std::vector<QString> ew::app::AiEmbeddingRequest::input
The texts to embed, in order (batched into one call; one entry is fine).
QString ew::app::AiEmbeddingRequest::model
The embeddings model to request (e.g. "text-embedding-3-small", a local model id).
AiEmbeddingResponse struct
struct ew::app::AiEmbeddingResponse
The embeddings for a request, or an error. Exactly one of vectors (on success) or error (on failure) is meaningful; ok distinguishes them.
Members
bool ew::app::AiEmbeddingResponse::ok = false
True when the model returned embeddings; false when the request errored.
std::vector<std::vector<float> > ew::app::AiEmbeddingResponse::vectors
One embedding vector per input text, in the same order as the request.
QString ew::app::AiEmbeddingResponse::error
A human-readable error message (when not ok).
TokenUsage ew::app::AiEmbeddingResponse::usage {}
The token usage the provider reported for this call (all zero when none was reported).
Functions
QString ew::app::buildEmbeddingRequestJson(const AiEmbeddingRequest &request)
Serializes request to an OpenAI-compatible embeddings request body (JSON). Pure and unit-testable – no network or key.
float ew::app::cosineSimilarity(const std::vector< float > &a, const std::vector< float > &b)
The cosine similarity of two embedding vectors, in [-1, 1] (higher = more semantically similar). Returns 0 when the vectors are empty, differ in length, or either has zero magnitude, so callers can rank by it without special-casing.
AiEmbeddingResponse ew::app::parseEmbeddingResponseJson(const QString &json)
Parses an OpenAI-compatible embeddings response body json into an AiEmbeddingResponse: on success the per-input embedding vectors (ordered by the response's "index"); on an API error the error message; and a clear error when the body is malformed or empty. Pure and unit-testable.