Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion rig/rig-core/src/providers/ollama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ enum ApiResponse<T> {
pub const ALL_MINILM: &str = "all-minilm";
pub const NOMIC_EMBED_TEXT: &str = "nomic-embed-text";

fn model_dimensions_from_identifier(identifier: &str) -> Option<usize> {
match identifier {
ALL_MINILM => Some(384),
NOMIC_EMBED_TEXT => Some(768),
_ => None,
}
}

Comment on lines +150 to +157
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part is largely unmaintainable, so we should avoid adding this in. It is usually quite trivial to find the dimension sizes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think this part is largely unmaintainable too. A better approach is to use embedding_model_with_ndims. I added it this way because I noticed that other modules did the same. openai/embedding.rs:row59

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah OpenAI only has 2/3 models so it's fine. Unfortunately for us, ollama seems to have an absolute tonne of them which means we can't reliably keep track of all of them

#[derive(Debug, Serialize, Deserialize)]
pub struct EmbeddingResponse {
pub model: String,
Expand Down Expand Up @@ -208,7 +216,11 @@ where
type Client = Client<T>;

fn make(client: &Self::Client, model: impl Into<String>, dims: Option<usize>) -> Self {
Self::new(client.clone(), model, dims.unwrap())
let model = model.into();
let dims = dims
.or(model_dimensions_from_identifier(&model))
.unwrap_or_default();
Self::new(client.clone(), model, dims)
}

const MAX_DOCUMENTS: usize = 1024;
Expand Down