feat: let workflow rag nodes select a RAG driver
`RagNode` gains an optional `driver`, forwarded into `RagInitConfig` so a graph node can build its knowledge base on duckdb instead of yaml. Nodes that name no driver forward `None`, which still resolves to yaml, so existing workflows are unaffected. An unknown driver is rejected up front rather than at construction time. `Rag::create` dispatches unknown drivers to its yaml catch-all, so a typo would otherwise embed every document and persist the bogus string, after which every subsequent load fails validation and the agent cannot start. The check asks `RagData::validate()` through a probe value instead of restating the list of valid drivers, so the two cannot drift.
This commit is contained in:
+72
-15
@@ -12,6 +12,7 @@ use crate::config::prompts::{
|
||||
DEFAULT_SPAWN_INSTRUCTIONS, DEFAULT_TEAMMATE_INSTRUCTIONS, DEFAULT_TODO_INSTRUCTIONS,
|
||||
DEFAULT_USER_INTERACTION_INSTRUCTIONS,
|
||||
};
|
||||
use crate::graph::types::RagNode;
|
||||
use crate::graph::{Graph, GraphParser, NodeType};
|
||||
use crate::rag::RagInitConfig;
|
||||
use crate::vault::SECRET_RE;
|
||||
@@ -952,6 +953,30 @@ fn resolve_document_paths(
|
||||
Ok(document_paths)
|
||||
}
|
||||
|
||||
/// How a graph rag node describes the knowledge base it wants built.
|
||||
///
|
||||
/// `driver` is forwarded as-is: `None` means the node did not ask for one, which
|
||||
/// `RagInitConfig` resolves to yaml, so workflows written before drivers existed
|
||||
/// keep their current storage.
|
||||
///
|
||||
/// Every field is now named explicitly, so adding one to `RagInitConfig` breaks
|
||||
/// this literal. That is deliberate: the new field then gets a decision about
|
||||
/// whether a rag node can drive it, instead of silently taking its default.
|
||||
fn rag_init_config(rag_node: &RagNode) -> RagInitConfig {
|
||||
RagInitConfig {
|
||||
embedding_model: rag_node.embedding_model.clone(),
|
||||
chunk_size: rag_node.chunk_size,
|
||||
chunk_overlap: rag_node.chunk_overlap,
|
||||
reranker_model: rag_node.reranker_model.clone(),
|
||||
top_k: rag_node.top_k,
|
||||
batch_size: rag_node.batch_size,
|
||||
extractor_model: rag_node.extractor_model.clone(),
|
||||
extractor_prompt: rag_node.extractor_prompt.clone(),
|
||||
graph_hops: rag_node.graph_hops,
|
||||
driver: rag_node.driver.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn init_graph_rags(
|
||||
app: &AppConfig,
|
||||
@@ -989,21 +1014,18 @@ async fn init_graph_rags(
|
||||
})
|
||||
.await?
|
||||
} else {
|
||||
let config = RagInitConfig {
|
||||
embedding_model: rag_node.embedding_model.clone(),
|
||||
chunk_size: rag_node.chunk_size,
|
||||
chunk_overlap: rag_node.chunk_overlap,
|
||||
reranker_model: rag_node.reranker_model.clone(),
|
||||
top_k: rag_node.top_k,
|
||||
batch_size: rag_node.batch_size,
|
||||
extractor_model: rag_node.extractor_model.clone(),
|
||||
extractor_prompt: rag_node.extractor_prompt.clone(),
|
||||
graph_hops: rag_node.graph_hops,
|
||||
// Graph-node RAGs are yaml-only: `RagNode` has no `driver` field, so
|
||||
// there is nothing to forward. The rest-pattern also keeps this literal
|
||||
// from breaking on future `RagInitConfig` additions.
|
||||
..Default::default()
|
||||
};
|
||||
// Checked before anything is built: an unknown driver would otherwise
|
||||
// fall through `Rag::create`'s catch-all to a yaml store, embed every
|
||||
// document, and persist the bogus driver string. The RAG would then be
|
||||
// rejected on every subsequent load, leaving the agent unstartable.
|
||||
// Graph validation catches this too, but it is skipped when
|
||||
// `validate_before_run` is off, so this guard is the load-bearing one.
|
||||
if let Some(driver) = &rag_node.driver
|
||||
&& let Some(message) = crate::graph::validator::rag_driver_error(driver)
|
||||
{
|
||||
bail!("rag node '{node_id}': {message}");
|
||||
}
|
||||
let config = rag_init_config(rag_node);
|
||||
let fully_specified = config.embedding_model.is_some()
|
||||
&& config.chunk_size.is_some()
|
||||
&& config.chunk_overlap.is_some();
|
||||
@@ -1337,4 +1359,39 @@ version: "1.0"
|
||||
|
||||
assert_eq!(meta.description, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rag_init_config_forwards_an_explicit_driver() {
|
||||
let node: RagNode =
|
||||
serde_yaml::from_str("documents: [\"./docs\"]\ndriver: duckdb\n").unwrap();
|
||||
|
||||
assert_eq!(rag_init_config(&node).driver.as_deref(), Some("duckdb"));
|
||||
}
|
||||
|
||||
/// A node that names no driver must forward `None`, which `RagInitConfig`
|
||||
/// documents as "yaml". Existing workflows therefore keep their yaml store.
|
||||
#[test]
|
||||
fn rag_init_config_leaves_the_driver_unset_by_default() {
|
||||
let node: RagNode = serde_yaml::from_str("documents: [\"./docs\"]\n").unwrap();
|
||||
|
||||
assert_eq!(rag_init_config(&node).driver, None);
|
||||
}
|
||||
|
||||
/// The driver must ride alongside the rest of the node's settings, not
|
||||
/// replace them.
|
||||
#[test]
|
||||
fn rag_init_config_forwards_the_other_settings_too() {
|
||||
let node: RagNode = serde_yaml::from_str(
|
||||
"documents: [\"./docs\"]\ndriver: duckdb\nchunk_size: 512\nchunk_overlap: 64\ntop_k: 7\nembedding_model: some:model\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let config = rag_init_config(&node);
|
||||
|
||||
assert_eq!(config.driver.as_deref(), Some("duckdb"));
|
||||
assert_eq!(config.chunk_size, Some(512));
|
||||
assert_eq!(config.chunk_overlap, Some(64));
|
||||
assert_eq!(config.top_k, Some(7));
|
||||
assert_eq!(config.embedding_model.as_deref(), Some("some:model"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user