diff --git a/core/src/blocks/data_source.rs b/core/src/blocks/data_source.rs index d9b4afae7632..92e882c17faf 100644 --- a/core/src/blocks/data_source.rs +++ b/core/src/blocks/data_source.rs @@ -55,12 +55,8 @@ impl DataSource { }) } - fn replace_query_variables(text: &str, env: &Env) -> Result { - replace_variables_in_string(text, "query", env) - } - fn query(&self, env: &Env) -> Result { - let mut query = Self::replace_query_variables(&self.query, env)?; + let mut query = replace_variables_in_string(&self.query, "query", env)?; // replace with ``` query = query.replace("", "```"); @@ -236,7 +232,36 @@ impl Block for DataSource { let filter = match config { Some(v) => match v.get("filter") { - Some(v) => Some(SearchFilter::from_json_str(v.to_string().as_str())?), + Some(v) => { + let mut filter = SearchFilter::from_json_str(v.to_string().as_str())?; + + match filter.tags.as_mut() { + Some(tags) => { + let replace_tags = |tags: &mut Vec, field: &str| { + for t in tags.iter_mut() { + *t = replace_variables_in_string(t, field, env)?; + } + Ok::<_, anyhow::Error>(()) + }; + + match tags.is_in.as_mut() { + Some(is_in) => { + replace_tags(is_in, "filter.tags.is_in")?; + } + None => (), + }; + match tags.is_not.as_mut() { + Some(is_not) => { + replace_tags(is_not, "filter.tags.is_not")?; + } + None => (), + }; + } + None => (), + }; + + Some(filter) + } _ => None, }, _ => None, diff --git a/docs/src/pages/core-blocks.mdx b/docs/src/pages/core-blocks.mdx index 54ffd80ffdda..59f03f15c2d9 100644 --- a/docs/src/pages/core-blocks.mdx +++ b/docs/src/pages/core-blocks.mdx @@ -454,5 +454,8 @@ for more details about how documents are chunked to enable semantic search. "timestamp": {"gt": 1675215950729, "lt": 1680012404017} } ``` + The `tags.in` and `tags.not` values can be templated using the + [Tera](https://keats.github.io/tera/docs/#templates) templating language (see the [LLM + block](/core-blocks#llm-block) documentation for more details on templating).