Template retrieval logic

This commit is contained in:
Mubelotix
2025-07-16 16:52:28 +02:00
parent f50a5b17b6
commit e124c161ec
4 changed files with 348 additions and 20 deletions

View File

@ -2041,7 +2041,7 @@ fn embedders(embedding_configs: Vec<IndexEmbeddingConfig>) -> Result<RuntimeEmbe
.into_iter()
.map(|fragment| {
let template = JsonTemplate::new(
embedder_options.fragment(&fragment.name).unwrap().clone(),
embedder_options.indexing_fragment(&fragment.name).unwrap().clone(),
)
.unwrap();

View File

@ -823,7 +823,26 @@ pub enum EmbedderOptions {
}
impl EmbedderOptions {
pub fn fragment(&self, name: &str) -> Option<&serde_json::Value> {
pub fn indexing_fragments(&self) -> Vec<String> {
match &self {
EmbedderOptions::HuggingFace(_)
| EmbedderOptions::OpenAi(_)
| EmbedderOptions::Ollama(_)
| EmbedderOptions::UserProvided(_) => vec![],
EmbedderOptions::Rest(embedder_options) => {
embedder_options.indexing_fragments.keys().cloned().collect()
}
EmbedderOptions::Composite(embedder_options) => {
if let SubEmbedderOptions::Rest(embedder_options) = &embedder_options.index {
embedder_options.indexing_fragments.keys().cloned().collect()
} else {
vec![]
}
}
}
}
pub fn indexing_fragment(&self, name: &str) -> Option<&serde_json::Value> {
match &self {
EmbedderOptions::HuggingFace(_)
| EmbedderOptions::OpenAi(_)
@ -841,6 +860,44 @@ impl EmbedderOptions {
}
}
}
pub fn search_fragments(&self) -> Vec<String> {
match &self {
EmbedderOptions::HuggingFace(_)
| EmbedderOptions::OpenAi(_)
| EmbedderOptions::Ollama(_)
| EmbedderOptions::UserProvided(_) => vec![],
EmbedderOptions::Rest(embedder_options) => {
embedder_options.search_fragments.keys().cloned().collect()
}
EmbedderOptions::Composite(embedder_options) => {
if let SubEmbedderOptions::Rest(embedder_options) = &embedder_options.search {
embedder_options.search_fragments.keys().cloned().collect()
} else {
vec![]
}
}
}
}
pub fn search_fragment(&self, name: &str) -> Option<&serde_json::Value> {
match &self {
EmbedderOptions::HuggingFace(_)
| EmbedderOptions::OpenAi(_)
| EmbedderOptions::Ollama(_)
| EmbedderOptions::UserProvided(_) => None,
EmbedderOptions::Rest(embedder_options) => {
embedder_options.search_fragments.get(name)
}
EmbedderOptions::Composite(embedder_options) => {
if let SubEmbedderOptions::Rest(embedder_options) = &embedder_options.search {
embedder_options.search_fragments.get(name)
} else {
None
}
}
}
}
}
impl Default for EmbedderOptions {