pub struct DynamicGraphModel {
pub name: String,
pub schema: Value,
pub description: Option<String>,
pub source: Option<String>,
}Expand description
A runtime representation of a graph model’s JSON schema.
Stores the JSON schema for a graph model so it can be serialized, transmitted between SDKs, and used for LLM structured output without requiring the concrete Rust type at runtime.
§Fields
name- Human-readable name for the model (e.g., “KnowledgeGraph”, “ProgrammingLanguage”)schema- The JSON schema as aserde_json::Valuedescription- Optional description of what the model representssource- Optional source identifier (e.g., “python-sdk”, “rust-sdk”)
Fields§
§name: StringHuman-readable name for the model.
schema: ValueThe JSON schema describing the model’s structure.
description: Option<String>Optional description of what the model represents.
source: Option<String>Optional source identifier (e.g., “python-sdk”, “rust-sdk”).
Implementations§
Source§impl DynamicGraphModel
impl DynamicGraphModel
Sourcepub fn from_type<T: JsonSchema>(name: impl Into<String>) -> Self
pub fn from_type<T: JsonSchema>(name: impl Into<String>) -> Self
Create a DynamicGraphModel from a Rust type that implements JsonSchema.
Generates the JSON schema at runtime via schemars and stores it alongside
the given name. The source field is automatically set to "rust-sdk".
§Arguments
name- Human-readable name for the model
§Example
use cognee_llm::DynamicGraphModel;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, JsonSchema, Clone)]
struct PersonGraph {
people: Vec<String>,
relationships: Vec<(String, String)>,
}
let model = DynamicGraphModel::from_type::<PersonGraph>("PersonGraph");
assert_eq!(model.name, "PersonGraph");
assert_eq!(model.source.as_deref(), Some("rust-sdk"));Sourcepub fn from_schema(name: impl Into<String>, schema: Value) -> Self
pub fn from_schema(name: impl Into<String>, schema: Value) -> Self
Create a DynamicGraphModel from a pre-existing JSON schema.
Use this when receiving a schema from an external source (e.g., the Python SDK serialized a Pydantic model to JSON schema).
§Arguments
name- Human-readable name for the modelschema- The JSON schema as aserde_json::Value
§Example
use cognee_llm::DynamicGraphModel;
let schema = serde_json::json!({
"type": "object",
"properties": {
"name": { "type": "string" }
},
"required": ["name"]
});
let model = DynamicGraphModel::from_schema("ExternalModel", schema);
assert_eq!(model.name, "ExternalModel");
assert!(model.source.is_none());Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Set an optional description on this model.
Sourcepub fn with_source(self, source: impl Into<String>) -> Self
pub fn with_source(self, source: impl Into<String>) -> Self
Set an optional source identifier on this model.
Sourcepub fn has_properties(&self) -> bool
pub fn has_properties(&self) -> bool
Check whether the schema has a "properties" key (i.e., looks like an object schema).
This is a lightweight structural check, not full JSON Schema validation.
For full structural validation, deserialize with serde_json::from_value::<T>()
which enforces all type constraints.
Sourcepub fn required_fields(&self) -> Option<Vec<&str>>
pub fn required_fields(&self) -> Option<Vec<&str>>
Get the list of required field names from the schema, if any.
Returns None if the schema has no "required" key. Returns Some(vec)
with the field names otherwise.
Sourcepub fn check_required_fields(&self, instance: &Value) -> Result<(), String>
pub fn check_required_fields(&self, instance: &Value) -> Result<(), String>
Check whether a JSON value has all the required fields defined in this schema.
This performs a lightweight check: it only verifies that required fields
exist as keys in the JSON object. It does not validate types or nested
structures. For full structural validation, use serde_json::from_value::<T>().
Returns Ok(()) if all required fields are present (or if there are no
required fields). Returns Err with a message listing missing fields.