| Crates.io | semantic-commands |
| lib.rs | semantic-commands |
| version | 0.1.1 |
| created_at | 2025-11-17 20:38:12.107591+00 |
| updated_at | 2025-11-17 21:31:33.614503+00 |
| description | A lightweight Rust framework for defining and executing semantic commands using text embeddings |
| homepage | |
| repository | https://github.com/SET001/semantic-commands |
| max_upload_size | |
| id | 1937454 |
| size | 112,397 |
A lightweight Rust framework for defining and executing semantic commands using text embeddings. Frontend‑agnostic and async‑first: route user phrases to your functions based on semantic similarity. Use it in CLI tools, services, web, or desktop applications.
Define Commands
async fn get_date(_ctx: Arc<()>) -> String {
"2025-11-05".to_string()
}
let command = Command {
name: "get_date".to_string(),
requires_confirmation: false,
executor: async_executor(get_date),
};
let inputs = vec![
Input::new("what's the date"),
];
Initialize SemanticCommands
let mut semantic_commands = SemanticCommands::new(
OpenAIEmbedder, // OpenAIEmbedder or implement your own.
NoCache, // PostgresCache | NoCache or implement your own.
AppContext // define your context which will be available in command executors.
);
semantic_commands.add_command(command, inputs);
Execute a Command
let result = semantic_commands.execute("what is the current BTC price?").await?;
The result should be then downcasted to whatever type returned by your executor:
println!("Date: {:?}", result.downcast::<anyhow::Result<String>>().unwrap().unwrap());
| Cache | Speed | Memory | Persistence | Use Case |
|---|---|---|---|---|
NoCache |
N/A | None | N/A | Testing, stateless |
InMemoryCache |
Fast | Unbounded | No | Services, bots |
PostgresCache |
Slow | DB-backed | Yes | Multi-instance |
openai (default) - OpenAI embedding providerin-memory-cache (default) - Fast in-memory LRU cache based on mokapostgres - PostgreSQL cache backend (implemented with sqlx)full - All features enabledUsing remote embedding providers (like OpenAI) sends input text to third‑party services. Do not embed secrets or private data you cannot share.
You can implement:
Embedder (e.g. local model)Cache