1use crate::client::Client;
2use crate::error::Result;
3use crate::models::{
4 DebugDistanceResponse, DebugGetEmbeddingsRequest, DebugGetEmbeddingsResponse,
5 DebugLevelsResponse, DebugNodeInfoResponse, DebugNodesAtLevelResponse,
6 DebugReferenceNodeResponse,
7};
8use std::collections::HashMap;
9
10impl Client {
11 pub async fn get_collection_distance(
13 &self,
14 collection_name: &str,
15 field: &str,
16 node_id: i32,
17 text: &str,
18 custom_matcher_text: Option<&str>,
19 ) -> Result<DebugDistanceResponse> {
20 let path = format!(
21 "/api/collections/v1/debug/{}/{}/distance/{}",
22 collection_name, field, node_id
23 );
24 let mut params = HashMap::new();
25 params.insert("text".to_string(), text.to_string());
26
27 if let Some(custom_text) = custom_matcher_text {
28 if !custom_text.is_empty() {
29 params.insert("custom_matcher_text".to_string(), custom_text.to_string());
30 }
31 }
32
33 self.do_request::<DebugDistanceResponse, ()>(
34 reqwest::Method::GET,
35 &path,
36 None,
37 Some(¶ms),
38 )
39 .await
40 }
41
42 pub async fn get_collection_node_info(
44 &self,
45 collection_name: &str,
46 field: &str,
47 node_id: i32,
48 ) -> Result<DebugNodeInfoResponse> {
49 let path = format!(
50 "/api/collections/v1/debug/{}/{}/nodes/{}",
51 collection_name, field, node_id
52 );
53 self.do_request::<DebugNodeInfoResponse, ()>(reqwest::Method::GET, &path, None, None)
54 .await
55 }
56
57 pub async fn get_collection_node_neighbors_at_level(
59 &self,
60 collection_name: &str,
61 field: &str,
62 node_id: i32,
63 level: i32,
64 limit: Option<i32>,
65 offset: Option<i32>,
66 ) -> Result<DebugNodeInfoResponse> {
67 let path = format!(
68 "/api/collections/v1/debug/{}/{}/nodes/{}/neighbors/{}",
69 collection_name, field, node_id, level
70 );
71
72 let mut params = HashMap::new();
73 if let Some(l) = limit {
74 params.insert("limit".to_string(), l.to_string());
75 }
76 if let Some(o) = offset {
77 params.insert("offset".to_string(), o.to_string());
78 }
79
80 self.do_request::<DebugNodeInfoResponse, ()>(
81 reqwest::Method::GET,
82 &path,
83 None,
84 if params.is_empty() {
85 None
86 } else {
87 Some(¶ms)
88 },
89 )
90 .await
91 }
92
93 pub async fn get_collection_levels(
95 &self,
96 collection_name: &str,
97 ) -> Result<DebugLevelsResponse> {
98 let path = format!("/api/collections/v1/debug/{}/levels", collection_name);
99 self.do_request::<DebugLevelsResponse, ()>(reqwest::Method::GET, &path, None, None)
100 .await
101 }
102
103 pub async fn get_collection_nodes_at_level(
105 &self,
106 collection_name: &str,
107 level: i32,
108 ) -> Result<DebugNodesAtLevelResponse> {
109 let path = format!(
110 "/api/collections/v1/debug/{}/levels/{}",
111 collection_name, level
112 );
113 self.do_request::<DebugNodesAtLevelResponse, ()>(reqwest::Method::GET, &path, None, None)
114 .await
115 }
116
117 pub async fn get_collection_node_by_reference_node_id(
119 &self,
120 collection_name: &str,
121 node_id: &str,
122 ) -> Result<DebugReferenceNodeResponse> {
123 let path = format!(
124 "/api/collections/v1/debug/{}/nodes/reference_node/{}",
125 collection_name, node_id
126 );
127 self.do_request::<DebugReferenceNodeResponse, ()>(reqwest::Method::GET, &path, None, None)
128 .await
129 }
130
131 pub async fn get_collection_embeddings(
133 &self,
134 collection_name: &str,
135 req: DebugGetEmbeddingsRequest,
136 ) -> Result<DebugGetEmbeddingsResponse> {
137 let path = format!("/api/collections/v1/debug/{}/embedding", collection_name);
138
139 self.do_request::<DebugGetEmbeddingsResponse, DebugGetEmbeddingsRequest>(
140 reqwest::Method::POST,
141 &path,
142 Some(&req),
143 None,
144 )
145 .await
146 }
147}