aleph_alpha_client/semantic_embedding/mod.rs
1mod embedding;
2mod embedding_batch;
3mod embedding_with_instruction;
4
5pub use embedding::{SemanticEmbeddingOutput, TaskSemanticEmbedding};
6pub use embedding_batch::{BatchSemanticEmbeddingOutput, TaskBatchSemanticEmbedding};
7pub use embedding_with_instruction::TaskSemanticEmbeddingWithInstruction;
8
9use serde::Serialize;
10use std::fmt::Debug;
11
12const DEFAULT_EMBEDDING_MODEL: &str = "luminous-base";
13const DEFAULT_EMBEDDING_MODEL_WITH_INSTRUCTION: &str = "pharia-1-embedding-4608-control";
14
15/// Appends model and hosting to the bare task
16/// `T` stands for [`TaskSemanticEmbedding`], [`TaskSemanticEmbeddingWithInstruction`] or
17/// [`TaskBatchSemanticEmbedding`].
18#[derive(Serialize, Debug)]
19struct RequestBody<'a, T: Serialize + Debug> {
20 /// Currently semantic embedding still requires a model parameter, even though "luminous-base"
21 /// is the only model to support it. This makes Semantic embedding both a Service and a Method.
22 model: &'a str,
23 #[serde(flatten)]
24 semantic_embedding_task: &'a T,
25}
26
27/// Allows you to choose a semantic representation fitting for your use case.
28#[derive(Serialize, Debug)]
29#[serde(rename_all = "snake_case")]
30pub enum SemanticRepresentation {
31 /// Useful for comparing prompts to each other, in use cases such as clustering, classification,
32 /// similarity, etc. `Symmetric` embeddings are intended to be compared with other `Symmetric`
33 /// embeddings.
34 Symmetric,
35 /// `Document` and `Query` are used together in use cases such as search where you want to
36 /// compare shorter queries against larger documents. `Document` embeddings are optimized for
37 /// larger pieces of text to compare queries against.
38 Document,
39 /// `Document` and `Query` are used together in use cases such as search where you want to
40 /// compare shorter queries against larger documents. `Query` embeddings are optimized for
41 /// shorter texts, such as questions or keywords.
42 Query,
43}