Request for review: semantic-commands crate (semantic routing via embeddings)

⚓ Rust    📅 2025-11-07    👤 surdeus    👁️ 3      

surdeus

Repo: https://github.com/SET001/semantic-commands

Goal:

Route natural language inputs to registered async commands using embeddings + cosine similarity.

Use cases: bots, CLI assistants, flexible command interfaces.

Core pieces:

  • Command { name, executor }
  • Input: normalized phrase + optional embedding cache
  • Traits: Embedder, Cache (OpenAI + Postgres implementations)
  • Execution returns Box<dyn Any + Send> (downcast at call site)

Example (conceptual):


sc.execute("what's the date?") -> should run registered async executor for date command

Questions:

  1. API naming: Command / Input / SemanticCommands—idiomatic?
  2. Executor signature: Arc -> Future<Result> boxed—better pattern?
  3. Returning Box: keep, or switch to enum / trait object?
  4. Embedding caching flow: update missing embeddings lazily vs precompute?
  5. find_similar implementation: any obvious perf / borrow improvements?
  6. Error strategy: still using anyhow::Result—should I introduce a crate Error enum now?
  7. async_trait usage: acceptable here or refactor to generic async fns?

Appreciate any feedback on ergonomics, structure, idiomatic Rust, and pitfalls. Thanks!

1 post - 1 participant

Read full topic

🏷️ Rust_feed