@@ -97,6 +97,7 @@ enum ResourceSpec {
97
97
commit : String ,
98
98
threshold : f32 ,
99
99
} ,
100
+ GetStatistics ,
100
101
}
101
102
102
103
#[ derive( Debug , Error ) ]
@@ -149,6 +150,7 @@ fn uri_to_spec(uri: &Uri) -> Result<ResourceSpec, SpecParseError> {
149
150
static ref RE_SEARCH : Regex = Regex :: new( r"^/search(/?)$" ) . unwrap( ) ;
150
151
static ref RE_SIMILAR : Regex = Regex :: new( r"^/similar(/?)$" ) . unwrap( ) ;
151
152
static ref RE_DUPLICATES : Regex = Regex :: new( r"^/duplicates(/?)$" ) . unwrap( ) ;
153
+ static ref RE_STATISTICS : Regex = Regex :: new( r"^/statistics$" ) . unwrap( ) ;
152
154
}
153
155
let path = uri. path ( ) ;
154
156
@@ -239,6 +241,8 @@ fn uri_to_spec(uri: &Uri) -> Result<ResourceSpec, SpecParseError> {
239
241
}
240
242
_ => Err ( SpecParseError :: NoCommitIdOrDomain ) ,
241
243
}
244
+ } else if RE_STATISTICS . is_match ( path) {
245
+ Ok ( ResourceSpec :: GetStatistics )
242
246
} else {
243
247
Err ( SpecParseError :: UnknownPath )
244
248
}
@@ -659,6 +663,11 @@ impl Service {
659
663
let result = self . get_similar_documents ( domain, commit, id, count) . await ;
660
664
string_response_or_error ( result)
661
665
}
666
+ Ok ( ResourceSpec :: GetStatistics ) => {
667
+ let statistics = self . vector_store . statistics ( ) ;
668
+ let json_string = serde_json:: to_string_pretty ( & statistics) . map_err ( |e| e. into ( ) ) ;
669
+ json_response_or_error ( json_string)
670
+ }
662
671
Ok ( _) => todo ! ( ) ,
663
672
Err ( e) => Ok ( Response :: builder ( )
664
673
. status ( StatusCode :: NOT_FOUND )
@@ -801,6 +810,21 @@ fn string_response_or_error(
801
810
}
802
811
}
803
812
813
+ fn json_response_or_error (
814
+ result : Result < String , ResponseError > ,
815
+ ) -> Result < Response < Body > , Infallible > {
816
+ match result {
817
+ Ok ( task_id) => Ok ( Response :: builder ( )
818
+ . header ( "Content-Type" , "application/json" )
819
+ . body ( task_id. into ( ) )
820
+ . unwrap ( ) ) ,
821
+ Err ( e) => Ok ( Response :: builder ( )
822
+ . status ( 400 )
823
+ . body ( e. to_string ( ) . into ( ) )
824
+ . unwrap ( ) ) ,
825
+ }
826
+ }
827
+
804
828
#[ derive( Debug , Error ) ]
805
829
enum AssignIndexError {
806
830
#[ error( "io error: {0}" ) ]
0 commit comments