Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Cognate
Type-safe LLM framework for Rust. Multi-provider support, compile-time validation, streaming, tool calling—all with zero-cost abstractions.
Overview
Cognate provides production-grade abstractions for building LLM-powered applications in Rust. Unlike fragmented HTTP clients or Python-style libraries, Cognate offers:
- Unified multi-provider interface (OpenAI, Anthropic, Groq, Ollama, custom)
- Type-safe tool calling via
#[derive(Tool)] - Compile-time prompt validation via
#[derive(Prompt)] - Production middleware (retry, rate-limit, tracing)
- Streaming-first design with proper error handling
- Axum web server integration out of the box
- RAG pipeline support with pluggable vector stores
Quick Links
- Documentation: https://docs.rs/cognate-core
- Examples: See examples/
- Contributing: CONTRIBUTING.md
- Architecture: ARCHITECTURE.md
- Getting Started: GETTING_STARTED.md
Why Cognate?
Feature Comparison
| Feature | Cognate | async-openai | rig |
|---|---|---|---|
| Multi-provider | OpenAI, Anthropic, Groq, Ollama | OpenAI only | OpenAI, Anthropic |
| Type-safe tools | #[derive(Tool)] with validation | Manual JSON | Runtime definition |
| Compile-time validation | Prompts checked at build time | No | No |
| Axum integration | Built-in extractors + middleware | No | No |
| Middleware system | Retry, rate-limit, tracing, observability | Basic retry | Limited |
| RAG support | Vector search + memory traits | No | No |
Performance
Cognate is designed for production workloads where latency and throughput matter.
| Metric | Cognate | async-openai (Rust) | Python LangChain |
|---|---|---|---|
| P50 Latency | <1ms (overhead) | <1ms (overhead) | 45ms |
| P99 Latency | <5ms (overhead) | <5ms (overhead) | 150ms |
| Requests/sec | 2500+ | 2800+ | 200-400 |
| Memory (RSS) | 12-15 MB | 12-15 MB | 120-150 MB |
| Compile time | 8-12s (clean) | 6-8s (clean) | N/A |
See BENCHMARKS.md for detailed metrics and reproducible measurements.
Installation
Add Cognate to your Cargo.toml:
[]
= "0.1"
= "0.1"
= "0.1"
= "0.1"
= { = "1.0", = ["full"] }
Quick Start
Basic Chat
use ;
use OpenAiProvider;
async
Type-Safe Tool Calling
use Tool;
use ;
use ;
use JsonSchema;
// Use in request
let request = new
.with_model
.with_messages
.with_tool;
Streaming Responses
use Provider;
use StreamExt;
let provider = /* ... */;
let mut stream = provider.stream.await?;
while let Some = stream.next.await
Architecture
Cognate is organized into specialized crates:
- cognate-core: Provider trait, request/response types, middleware system
- cognate-providers: OpenAI, Anthropic, retry, fallback implementations
- cognate-tools: Tool dispatch, automatic execution loop, #[derive(Tool)]
- cognate-prompts: Template system, compile-time validation, #[derive(Prompt)]
- cognate-rag: Vector search traits, memory abstraction, embedding utilities
- cognate-axum: Axum extractors, middleware layers, web integration
- cognate-cli: CLI tools for development and testing
Examples
All examples are in the respective crate directories:
- Simple Chat - Basic API usage
- Streaming Chat - Response streaming
- Tool Usage - Tool calling and dispatch
- Agent Loop - Multi-turn tool-using agent
- RAG Pipeline - Search + generation
- Axum ChatGPT Clone - Web server
Run an example:
Configuration
OpenAI Provider
use ;
use Duration;
let provider = new?
.with_timeout
.with_retry;
Custom Providers
Implement the Provider trait:
use ;
use async_trait;
;
Production Considerations
Observability
Cognate integrates with standard Rust tracing:
use ;
let span = span!;
let _guard = span.enter;
let response = provider.complete.await?;
Error Handling
Comprehensive error types:
use ;
match provider.complete.await
Testing
Cognate includes a mock provider for testing:
use MockProvider;
let mock = new
.queue_response;
let response = mock.complete.await?;
Status
Cognate is in active development (v0.1.0). The API is stable and suitable for production use.
- All 9 crates compile cleanly
- 17 unit tests + 7 doc tests passing
- Compatible with Rust 1.70 and newer
- Production middleware included
- Streaming support verified
License
Dual-licensed under MIT and Apache-2.0.
Choose whichever license works best for your project.
Contributing
Contributions are welcome. Please read CONTRIBUTING.md first.
Development setup:
Support
- Documentation: https://docs.rs/cognate-core
- Examples: See examples/
- Issues: https://github.com/YOUR_ORG/cognate/issues
Roadmap
- Vector store integrations (Qdrant, Pinecone, Weaviate)
- Additional providers (Groq, Ollama embedded)
- Streaming cost estimation
- Advanced caching layer
- Web dashboard for monitoring