Skip to main content

synaptic_cohere/
lib.rs

1//! Cohere integration for Synaptic.
2//!
3//! This crate provides [`CohereReranker`], a reranker that uses the
4//! [Cohere Rerank API](https://docs.cohere.com/reference/rerank) to
5//! reorder documents by relevance to a query.
6//!
7//! When the `retrieval` feature is enabled, `CohereReranker` also implements
8//! the [`DocumentCompressor`](synaptic_retrieval::DocumentCompressor) trait,
9//! making it usable with
10//! [`ContextualCompressionRetriever`](synaptic_retrieval::ContextualCompressionRetriever).
11//!
12//! # Example
13//!
14//! ```rust,no_run
15//! use synaptic_cohere::{CohereReranker, CohereRerankerConfig};
16//! use synaptic_core::Document;
17//!
18//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
19//! let config = CohereRerankerConfig::new("your-api-key")
20//!     .with_top_n(3);
21//! let reranker = CohereReranker::new(config);
22//!
23//! let docs = vec![
24//!     Document::new("1", "Rust is a systems programming language"),
25//!     Document::new("2", "Python is great for data science"),
26//! ];
27//!
28//! let reranked = reranker.rerank("systems programming", docs, None).await?;
29//! # Ok(())
30//! # }
31//! ```
32
33mod embeddings;
34mod reranker;
35
36pub use embeddings::{CohereEmbeddings, CohereEmbeddingsConfig, CohereInputType};
37pub use reranker::{CohereReranker, CohereRerankerConfig};
38
39// Re-export core types for convenience.
40pub use synaptic_core::Document;