Skip to main content

detect_namespace

Function detect_namespace 

Source
pub fn detect_namespace(
    explicit: Option<&str>,
) -> Result<NamespaceResolution, AppError>
Expand description

Resolves the active namespace, returning a struct with the source and current directory.

Precedence: explicit flag > SQLITE_GRAPHRAG_NAMESPACE > fallback "global".

§Errors

Returns AppError::Validation if the resolved namespace contains invalid characters.

§Examples

use sqlite_graphrag::namespace::{detect_namespace, NamespaceSource};

// With an explicit flag, the source is `ExplicitFlag`.
let res = detect_namespace(Some("producao")).unwrap();
assert_eq!(res.namespace, "producao");
assert_eq!(res.source, NamespaceSource::ExplicitFlag);
use sqlite_graphrag::namespace::{detect_namespace, NamespaceSource};

// Without any explicit configuration, fallback is "global".
// Removes env var to guarantee deterministic behaviour.
std::env::remove_var("SQLITE_GRAPHRAG_NAMESPACE");
let res = detect_namespace(None).unwrap();
assert_eq!(res.namespace, "global");
assert_eq!(res.source, NamespaceSource::Default);