pub struct Client { /* private fields */ }Expand description
A connected RCP client.
Implementations§
Source§impl Client
impl Client
Sourcepub fn connect_stdio<S: AsRef<str>>(argv: &[S]) -> Result<Client, RcpError>
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"].
Sourcepub fn connect_http(base_url: &str) -> Result<Client, RcpError>
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".
Sourcepub fn protocol_version(&self) -> i64
pub fn protocol_version(&self) -> i64
Examples found in repository?
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}Sourcepub fn server(&self) -> &Json
pub fn server(&self) -> &Json
Examples found in repository?
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}Sourcepub fn capabilities(&self) -> &Json
pub fn capabilities(&self) -> &Json
Examples found in repository?
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}Sourcepub fn supports(&self, cap: Capability) -> bool
pub fn supports(&self, cap: Capability) -> bool
Examples found in repository?
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}Sourcepub fn embed(
&mut self,
texts: &[&str],
kind: Option<&str>,
) -> Result<Vec<Vec<f64>>, RcpError>
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?
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}Sourcepub fn embed_sparse(&mut self, texts: &[&str]) -> Result<Json, RcpError>
pub fn embed_sparse(&mut self, texts: &[&str]) -> Result<Json, RcpError>
Learned-sparse (SPLADE) terms → raw result { sparse: [...] }.
Sourcepub fn embed_multi(&mut self, inputs: Vec<Json>) -> Result<Json, RcpError>
pub fn embed_multi(&mut self, inputs: Vec<Json>) -> Result<Json, RcpError>
Per-token multi-vector (ColBERT/ColPali) → { matrices, dimension }.
Sourcepub fn rerank(
&mut self,
query: &str,
passages: &[&str],
) -> Result<Vec<f64>, RcpError>
pub fn rerank( &mut self, query: &str, passages: &[&str], ) -> Result<Vec<f64>, RcpError>
Cross-encoder rerank → one score per passage.
Sourcepub fn search(
&mut self,
query: &str,
k: i64,
opts: Option<Json>,
) -> Result<SearchResult, RcpError>
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).
Sourcepub fn retrieve(&mut self, query: &str, k: i64) -> Result<Vec<Hit>, RcpError>
pub fn retrieve(&mut self, query: &str, k: i64) -> Result<Vec<Hit>, RcpError>
Convenience over search → just the hits.
Examples found in repository?
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}Sourcepub fn graph(
&mut self,
op: &str,
params: Option<Json>,
) -> Result<Json, RcpError>
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?
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}Sourcepub fn transform(&mut self, query: &str, method: &str) -> Result<Json, RcpError>
pub fn transform(&mut self, query: &str, method: &str) -> Result<Json, RcpError>
Query transform (HyDE, expansion, …) → raw result (spec §7.8).
Sourcepub fn index_add(&mut self, params: Json) -> Result<Json, RcpError>
pub fn index_add(&mut self, params: Json) -> Result<Json, RcpError>
Add documents to the corpus (spec §7.10).
Sourcepub fn index_delete(&mut self, params: Json) -> Result<Json, RcpError>
pub fn index_delete(&mut self, params: Json) -> Result<Json, RcpError>
Delete documents by id or filter (spec §7.11).
Sourcepub fn catalog(&mut self) -> Result<Json, RcpError>
pub fn catalog(&mut self) -> Result<Json, RcpError>
List downstream engines of an aggregator (spec §7.12).
Sourcepub fn feedback(
&mut self,
signals: Vec<Json>,
opts: Option<Json>,
) -> Result<Json, RcpError>
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.
Sourcepub fn memory_build(&mut self, params: Option<Json>) -> Result<Json, RcpError>
pub fn memory_build(&mut self, params: Option<Json>) -> Result<Json, RcpError>
Build or update a global/session memory (spec §7.17) → { memoryId, tokens? }.
Sourcepub fn memory_recall(
&mut self,
query: &str,
opts: Option<Json>,
) -> Result<Json, RcpError>
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? }.
Sourcepub fn info(&mut self) -> Result<Json, RcpError>
pub fn info(&mut self) -> Result<Json, RcpError>
Re-fetch identity + capabilities without re-initialising.
Sourcepub fn call(&mut self, method: &str, params: Json) -> Result<Json, RcpError>
pub fn call(&mut self, method: &str, params: Json) -> Result<Json, RcpError>
Escape hatch: invoke an arbitrary method with raw params.
Sourcepub fn ping(&mut self, nonce: Option<Json>) -> Result<Json, RcpError>
pub fn ping(&mut self, nonce: Option<Json>) -> Result<Json, RcpError>
Liveness check; echoes { nonce } when a nonce is given (spec §9).
Sourcepub fn shutdown(&mut self)
pub fn shutdown(&mut self)
Politely ask the server to stop, then close the transport. Never errors.
Examples found in repository?
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}