Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

A connected RCP client.

Implementations§

Source§

impl Client

Source

pub fn connect_stdio<S: AsRef<str>>(argv: &[S]) -> Result<Client, RcpError>

Spawn an RCP server subprocess and connect. argv e.g. ["python3", "srv.py"].

Source

pub fn connect_http(base_url: &str) -> Result<Client, RcpError>

Connect to an HTTP RCP server, e.g. "http://127.0.0.1:8000/rcp".

Source

pub fn protocol_version(&self) -> i64

Examples found in repository?
examples/example_client.rs (line 20)
8fn main() -> Result<(), rcp::RcpError> {
9    // The example_server binary sits next to this one in target/.../examples/.
10    let exe = std::env::current_exe().expect("current exe");
11    let server = exe.parent().unwrap().join("example_server");
12    let server = server.to_string_lossy().to_string();
13
14    let mut c = rcp::connect_stdio(&[server.as_str()])?;
15
16    println!(
17        "connected to {} v{} (RCP/{})",
18        c.server().get_str("name").unwrap_or("?"),
19        c.server().get_str("version").unwrap_or("?"),
20        c.protocol_version()
21    );
22    if let Some(caps) = c.capabilities().as_object() {
23        let keys: Vec<&str> = caps.iter().map(|(k, _)| k.as_str()).collect();
24        println!("capabilities: {:?}", keys);
25    }
26
27    if c.supports(Capability::Embed) {
28        let vecs = c.embed(&["hello world"], None)?;
29        println!("embed      -> {} vector(s), dim={}", vecs.len(), vecs[0].len());
30    }
31
32    if c.supports(Capability::Retrieve) {
33        println!("retrieve   ->");
34        for h in c.retrieve("landmark in the French capital", 2)? {
35            let snippet: String = h.text.chars().take(48).collect();
36            println!("   {}  score={:.3}  {}", h.id, h.score, snippet);
37        }
38    }
39
40    if c.supports(Capability::Graph) {
41        let g = c.graph("global", Some(rcp::obj(&[("query", "anything".into())])))?;
42        println!("graph      -> {}", g);
43    }
44
45    c.shutdown();
46    Ok(())
47}
Source

pub fn server(&self) -> &Json

Examples found in repository?
examples/example_client.rs (line 18)
8fn main() -> Result<(), rcp::RcpError> {
9    // The example_server binary sits next to this one in target/.../examples/.
10    let exe = std::env::current_exe().expect("current exe");
11    let server = exe.parent().unwrap().join("example_server");
12    let server = server.to_string_lossy().to_string();
13
14    let mut c = rcp::connect_stdio(&[server.as_str()])?;
15
16    println!(
17        "connected to {} v{} (RCP/{})",
18        c.server().get_str("name").unwrap_or("?"),
19        c.server().get_str("version").unwrap_or("?"),
20        c.protocol_version()
21    );
22    if let Some(caps) = c.capabilities().as_object() {
23        let keys: Vec<&str> = caps.iter().map(|(k, _)| k.as_str()).collect();
24        println!("capabilities: {:?}", keys);
25    }
26
27    if c.supports(Capability::Embed) {
28        let vecs = c.embed(&["hello world"], None)?;
29        println!("embed      -> {} vector(s), dim={}", vecs.len(), vecs[0].len());
30    }
31
32    if c.supports(Capability::Retrieve) {
33        println!("retrieve   ->");
34        for h in c.retrieve("landmark in the French capital", 2)? {
35            let snippet: String = h.text.chars().take(48).collect();
36            println!("   {}  score={:.3}  {}", h.id, h.score, snippet);
37        }
38    }
39
40    if c.supports(Capability::Graph) {
41        let g = c.graph("global", Some(rcp::obj(&[("query", "anything".into())])))?;
42        println!("graph      -> {}", g);
43    }
44
45    c.shutdown();
46    Ok(())
47}
Source

pub fn capabilities(&self) -> &Json

Examples found in repository?
examples/example_client.rs (line 22)
8fn main() -> Result<(), rcp::RcpError> {
9    // The example_server binary sits next to this one in target/.../examples/.
10    let exe = std::env::current_exe().expect("current exe");
11    let server = exe.parent().unwrap().join("example_server");
12    let server = server.to_string_lossy().to_string();
13
14    let mut c = rcp::connect_stdio(&[server.as_str()])?;
15
16    println!(
17        "connected to {} v{} (RCP/{})",
18        c.server().get_str("name").unwrap_or("?"),
19        c.server().get_str("version").unwrap_or("?"),
20        c.protocol_version()
21    );
22    if let Some(caps) = c.capabilities().as_object() {
23        let keys: Vec<&str> = caps.iter().map(|(k, _)| k.as_str()).collect();
24        println!("capabilities: {:?}", keys);
25    }
26
27    if c.supports(Capability::Embed) {
28        let vecs = c.embed(&["hello world"], None)?;
29        println!("embed      -> {} vector(s), dim={}", vecs.len(), vecs[0].len());
30    }
31
32    if c.supports(Capability::Retrieve) {
33        println!("retrieve   ->");
34        for h in c.retrieve("landmark in the French capital", 2)? {
35            let snippet: String = h.text.chars().take(48).collect();
36            println!("   {}  score={:.3}  {}", h.id, h.score, snippet);
37        }
38    }
39
40    if c.supports(Capability::Graph) {
41        let g = c.graph("global", Some(rcp::obj(&[("query", "anything".into())])))?;
42        println!("graph      -> {}", g);
43    }
44
45    c.shutdown();
46    Ok(())
47}
Source

pub fn supports(&self, cap: Capability) -> bool

Examples found in repository?
examples/example_client.rs (line 27)
8fn main() -> Result<(), rcp::RcpError> {
9    // The example_server binary sits next to this one in target/.../examples/.
10    let exe = std::env::current_exe().expect("current exe");
11    let server = exe.parent().unwrap().join("example_server");
12    let server = server.to_string_lossy().to_string();
13
14    let mut c = rcp::connect_stdio(&[server.as_str()])?;
15
16    println!(
17        "connected to {} v{} (RCP/{})",
18        c.server().get_str("name").unwrap_or("?"),
19        c.server().get_str("version").unwrap_or("?"),
20        c.protocol_version()
21    );
22    if let Some(caps) = c.capabilities().as_object() {
23        let keys: Vec<&str> = caps.iter().map(|(k, _)| k.as_str()).collect();
24        println!("capabilities: {:?}", keys);
25    }
26
27    if c.supports(Capability::Embed) {
28        let vecs = c.embed(&["hello world"], None)?;
29        println!("embed      -> {} vector(s), dim={}", vecs.len(), vecs[0].len());
30    }
31
32    if c.supports(Capability::Retrieve) {
33        println!("retrieve   ->");
34        for h in c.retrieve("landmark in the French capital", 2)? {
35            let snippet: String = h.text.chars().take(48).collect();
36            println!("   {}  score={:.3}  {}", h.id, h.score, snippet);
37        }
38    }
39
40    if c.supports(Capability::Graph) {
41        let g = c.graph("global", Some(rcp::obj(&[("query", "anything".into())])))?;
42        println!("graph      -> {}", g);
43    }
44
45    c.shutdown();
46    Ok(())
47}
Source

pub fn embed( &mut self, texts: &[&str], kind: Option<&str>, ) -> Result<Vec<Vec<f64>>, RcpError>

Dense embeddings → one Vec<f64> per input. kind selects asymmetric pooling.

Examples found in repository?
examples/example_client.rs (line 28)
8fn main() -> Result<(), rcp::RcpError> {
9    // The example_server binary sits next to this one in target/.../examples/.
10    let exe = std::env::current_exe().expect("current exe");
11    let server = exe.parent().unwrap().join("example_server");
12    let server = server.to_string_lossy().to_string();
13
14    let mut c = rcp::connect_stdio(&[server.as_str()])?;
15
16    println!(
17        "connected to {} v{} (RCP/{})",
18        c.server().get_str("name").unwrap_or("?"),
19        c.server().get_str("version").unwrap_or("?"),
20        c.protocol_version()
21    );
22    if let Some(caps) = c.capabilities().as_object() {
23        let keys: Vec<&str> = caps.iter().map(|(k, _)| k.as_str()).collect();
24        println!("capabilities: {:?}", keys);
25    }
26
27    if c.supports(Capability::Embed) {
28        let vecs = c.embed(&["hello world"], None)?;
29        println!("embed      -> {} vector(s), dim={}", vecs.len(), vecs[0].len());
30    }
31
32    if c.supports(Capability::Retrieve) {
33        println!("retrieve   ->");
34        for h in c.retrieve("landmark in the French capital", 2)? {
35            let snippet: String = h.text.chars().take(48).collect();
36            println!("   {}  score={:.3}  {}", h.id, h.score, snippet);
37        }
38    }
39
40    if c.supports(Capability::Graph) {
41        let g = c.graph("global", Some(rcp::obj(&[("query", "anything".into())])))?;
42        println!("graph      -> {}", g);
43    }
44
45    c.shutdown();
46    Ok(())
47}
Source

pub fn embed_sparse(&mut self, texts: &[&str]) -> Result<Json, RcpError>

Learned-sparse (SPLADE) terms → raw result { sparse: [...] }.

Source

pub fn embed_multi(&mut self, inputs: Vec<Json>) -> Result<Json, RcpError>

Per-token multi-vector (ColBERT/ColPali) → { matrices, dimension }.

Source

pub fn rerank( &mut self, query: &str, passages: &[&str], ) -> Result<Vec<f64>, RcpError>

Cross-encoder rerank → one score per passage.

Source

pub fn search( &mut self, query: &str, k: i64, opts: Option<Json>, ) -> Result<SearchResult, RcpError>

Full retrieve → hits, usage, and an optional page cursor (spec §7.6).

Source

pub fn retrieve(&mut self, query: &str, k: i64) -> Result<Vec<Hit>, RcpError>

Convenience over search → just the hits.

Examples found in repository?
examples/example_client.rs (line 34)
8fn main() -> Result<(), rcp::RcpError> {
9    // The example_server binary sits next to this one in target/.../examples/.
10    let exe = std::env::current_exe().expect("current exe");
11    let server = exe.parent().unwrap().join("example_server");
12    let server = server.to_string_lossy().to_string();
13
14    let mut c = rcp::connect_stdio(&[server.as_str()])?;
15
16    println!(
17        "connected to {} v{} (RCP/{})",
18        c.server().get_str("name").unwrap_or("?"),
19        c.server().get_str("version").unwrap_or("?"),
20        c.protocol_version()
21    );
22    if let Some(caps) = c.capabilities().as_object() {
23        let keys: Vec<&str> = caps.iter().map(|(k, _)| k.as_str()).collect();
24        println!("capabilities: {:?}", keys);
25    }
26
27    if c.supports(Capability::Embed) {
28        let vecs = c.embed(&["hello world"], None)?;
29        println!("embed      -> {} vector(s), dim={}", vecs.len(), vecs[0].len());
30    }
31
32    if c.supports(Capability::Retrieve) {
33        println!("retrieve   ->");
34        for h in c.retrieve("landmark in the French capital", 2)? {
35            let snippet: String = h.text.chars().take(48).collect();
36            println!("   {}  score={:.3}  {}", h.id, h.score, snippet);
37        }
38    }
39
40    if c.supports(Capability::Graph) {
41        let g = c.graph("global", Some(rcp::obj(&[("query", "anything".into())])))?;
42        println!("graph      -> {}", g);
43    }
44
45    c.shutdown();
46    Ok(())
47}
Source

pub fn graph( &mut self, op: &str, params: Option<Json>, ) -> Result<Json, RcpError>

GraphRAG op (“local”|“global”|…) → raw result (spec §7.9).

Examples found in repository?
examples/example_client.rs (line 41)
8fn main() -> Result<(), rcp::RcpError> {
9    // The example_server binary sits next to this one in target/.../examples/.
10    let exe = std::env::current_exe().expect("current exe");
11    let server = exe.parent().unwrap().join("example_server");
12    let server = server.to_string_lossy().to_string();
13
14    let mut c = rcp::connect_stdio(&[server.as_str()])?;
15
16    println!(
17        "connected to {} v{} (RCP/{})",
18        c.server().get_str("name").unwrap_or("?"),
19        c.server().get_str("version").unwrap_or("?"),
20        c.protocol_version()
21    );
22    if let Some(caps) = c.capabilities().as_object() {
23        let keys: Vec<&str> = caps.iter().map(|(k, _)| k.as_str()).collect();
24        println!("capabilities: {:?}", keys);
25    }
26
27    if c.supports(Capability::Embed) {
28        let vecs = c.embed(&["hello world"], None)?;
29        println!("embed      -> {} vector(s), dim={}", vecs.len(), vecs[0].len());
30    }
31
32    if c.supports(Capability::Retrieve) {
33        println!("retrieve   ->");
34        for h in c.retrieve("landmark in the French capital", 2)? {
35            let snippet: String = h.text.chars().take(48).collect();
36            println!("   {}  score={:.3}  {}", h.id, h.score, snippet);
37        }
38    }
39
40    if c.supports(Capability::Graph) {
41        let g = c.graph("global", Some(rcp::obj(&[("query", "anything".into())])))?;
42        println!("graph      -> {}", g);
43    }
44
45    c.shutdown();
46    Ok(())
47}
Source

pub fn transform(&mut self, query: &str, method: &str) -> Result<Json, RcpError>

Query transform (HyDE, expansion, …) → raw result (spec §7.8).

Source

pub fn index_add(&mut self, params: Json) -> Result<Json, RcpError>

Add documents to the corpus (spec §7.10).

Source

pub fn index_delete(&mut self, params: Json) -> Result<Json, RcpError>

Delete documents by id or filter (spec §7.11).

Source

pub fn catalog(&mut self) -> Result<Json, RcpError>

List downstream engines of an aggregator (spec §7.12).

Source

pub fn feedback( &mut self, signals: Vec<Json>, opts: Option<Json>, ) -> Result<Json, RcpError>

Send client→server relevance/reward/integrity signals (spec §7.16). Each signal REQUIRES hitId. Returns { accepted }; side-effect only.

Source

pub fn memory_build(&mut self, params: Option<Json>) -> Result<Json, RcpError>

Build or update a global/session memory (spec §7.17) → { memoryId, tokens? }.

Source

pub fn memory_recall( &mut self, query: &str, opts: Option<Json>, ) -> Result<Json, RcpError>

Recall clues / entry-points from a memory (spec §7.17) → { clues, hits? }.

Source

pub fn info(&mut self) -> Result<Json, RcpError>

Re-fetch identity + capabilities without re-initialising.

Source

pub fn call(&mut self, method: &str, params: Json) -> Result<Json, RcpError>

Escape hatch: invoke an arbitrary method with raw params.

Source

pub fn ping(&mut self, nonce: Option<Json>) -> Result<Json, RcpError>

Liveness check; echoes { nonce } when a nonce is given (spec §9).

Source

pub fn shutdown(&mut self)

Politely ask the server to stop, then close the transport. Never errors.

Examples found in repository?
examples/example_client.rs (line 45)
8fn main() -> Result<(), rcp::RcpError> {
9    // The example_server binary sits next to this one in target/.../examples/.
10    let exe = std::env::current_exe().expect("current exe");
11    let server = exe.parent().unwrap().join("example_server");
12    let server = server.to_string_lossy().to_string();
13
14    let mut c = rcp::connect_stdio(&[server.as_str()])?;
15
16    println!(
17        "connected to {} v{} (RCP/{})",
18        c.server().get_str("name").unwrap_or("?"),
19        c.server().get_str("version").unwrap_or("?"),
20        c.protocol_version()
21    );
22    if let Some(caps) = c.capabilities().as_object() {
23        let keys: Vec<&str> = caps.iter().map(|(k, _)| k.as_str()).collect();
24        println!("capabilities: {:?}", keys);
25    }
26
27    if c.supports(Capability::Embed) {
28        let vecs = c.embed(&["hello world"], None)?;
29        println!("embed      -> {} vector(s), dim={}", vecs.len(), vecs[0].len());
30    }
31
32    if c.supports(Capability::Retrieve) {
33        println!("retrieve   ->");
34        for h in c.retrieve("landmark in the French capital", 2)? {
35            let snippet: String = h.text.chars().take(48).collect();
36            println!("   {}  score={:.3}  {}", h.id, h.score, snippet);
37        }
38    }
39
40    if c.supports(Capability::Graph) {
41        let g = c.graph("global", Some(rcp::obj(&[("query", "anything".into())])))?;
42        println!("graph      -> {}", g);
43    }
44
45    c.shutdown();
46    Ok(())
47}

Auto Trait Implementations§

§

impl !RefUnwindSafe for Client

§

impl !Send for Client

§

impl !Sync for Client

§

impl !UnwindSafe for Client

§

impl Freeze for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.