Crates.io | anda_kip |
lib.rs | anda_kip |
version | 0.5.14 |
created_at | 2025-06-10 15:17:13.648549+00 |
updated_at | 2025-08-16 11:15:43.382548+00 |
description | A Rust SDK of KIP (Knowledge Interaction Protocol) for building sustainable AI knowledge memory systems. |
homepage | |
repository | https://github.com/ldclabs/anda_db/tree/main/rs/anda_kip |
max_upload_size | |
id | 1707242 |
size | 299,863 |
A Rust SDK of KIP (Knowledge Interaction Protocol) for building sustainable AI knowledge memory systems.
🧬 KIP (Knowledge Interaction Protocol) is a knowledge memory interaction protocol designed for Large Language Models (LLMs), aimed at building sustainable learning and self-evolving knowledge memory systems for AI Agents.
This crate provides a complete Rust SDK of the KIP specification, offering:
This implementation follows the official KIP specification. For detailed information about the protocol, syntax, and semantics, please refer to:
👉 KIP Specification
Add this to your Cargo.toml
:
[dependencies]
anda_kip = "0.4"
use anda_kip::{parse_kip, Command, Executor, Response, KipError};
// Parse a KQL query
let query = parse_kip(r#"
FIND(?drug.name, ?drug.attributes.risk_level)
WHERE {
?drug {type: "Drug"}
?headache {name: "Headache"}
(?drug, "treats", ?headache)
FILTER(?drug.attributes.risk_level < 3)
}
ORDER BY ?drug.attributes.risk_level ASC
LIMIT 10
"#)?;
// Parse a KML statement
let statement = parse_kip(r#"
UPSERT {
CONCEPT ?new_drug {
{ type: "Drug", name: "Aspirin" }
SET ATTRIBUTES {
molecular_formula: "C9H8O4",
risk_level: 1
}
SET PROPOSITIONS {
("treats", { type: "Symptom", name: "Headache" })
("is_class_of", { type: "DrugClass", name: "NSAID" })
}
}
}
WITH METADATA {
source: "Medical Database v2.1",
confidence: 0.95
}
"#)?;
// Parse a META command
let meta = parse_kip("DESCRIBE PRIMER")?;
use anda_kip::{Executor, Command, Json, KipError, Response};
use async_trait::async_trait;
pub struct MyKnowledgeGraph {
// Your knowledge graph implementation
}
#[async_trait(?Send)]
impl Executor for MyKnowledgeGraph {
async fn execute(&self, command: Command, dry_run: bool) -> Response {
match command {
Command::Kql(query) => {
// Execute KQL query against your knowledge graph
todo!("Implement KQL execution")
},
Command::Kml(statement) => {
// Execute KML statement to modify knowledge graph
todo!("Implement KML execution")
},
Command::Meta(meta_cmd) => {
// Execute META command for introspection
todo!("Implement META execution")
}
}
}
}
use anda_kip::{execute_kip, Request, Response};
// Using the high-level execution function
let executor = MyKnowledgeGraph::new();
let response = execute_kip(&executor, "FIND(?x) WHERE { ?x {type: \"Drug\"} }").await?;
// Using structured requests with parameters
let request = Request {
command: "FIND(?drug) WHERE { ?drug {type: \"Drug\", name: $drug_name} }".to_string(),
parameters: [("drug_name".to_string(), json!("Aspirin"))].into_iter().collect(),
dry_run: false,
};
let response = request.execute(&executor).await?;
The crate is organized into several key modules:
ast
: Abstract Syntax Tree definitions for all KIP constructscapsule
: KIP Genesis Capsuleserror
: Comprehensive error types and handlingexecutor
: Execution framework and traitsparser
: Nom-based parsers for KQL, KML, and META commandsrequest
: Request/Response structures for JSON-based communicationtypes
: KIP Entity TypesWe welcome contributions! Please feel free to submit issues, feature requests, or pull requests.
Copyright © 2025 LDC Labs.
anda_kip
is licensed under the MIT License. See LICENSE for the full license text.