@@ -25,10 +25,10 @@ pub fn handler() -> ApiRouter {
25
25
. api_route ( "/:collection_name" , post ( query_collection) )
26
26
. api_route ( "/:collection_name" , get ( get_collection_info) )
27
27
. api_route ( "/:collection_name" , delete ( delete_collection) )
28
- . api_route ( "/:collection_name/insert" , post ( insert_into_collection) )
29
28
. api_route ( "/:collection_name/embeddings" , get ( get_embeddings) )
30
29
. api_route ( "/:collection_name/embeddings" , post ( query_embeddings) )
31
30
. api_route ( "/:collection_name/embeddings" , delete ( delete_embeddings) )
31
+ . api_route ( "/:collection_name/embeddings/:embedding_id" , put ( insert_into_collection) )
32
32
. api_route ( "/:collection_name/embeddings/:embedding_id" , get ( get_embedding) )
33
33
. api_route ( "/:collection_name/embeddings/:embedding_id" , delete ( delete_embedding) ) ,
34
34
)
@@ -162,16 +162,29 @@ async fn delete_collection(
162
162
}
163
163
}
164
164
165
+ #[ derive( Debug , serde:: Deserialize , JsonSchema ) ]
166
+ struct EmbeddingData {
167
+ /// Vector computed from a text chunk
168
+ vector : Vec < f32 > ,
169
+ /// Metadata about the source text
170
+ metadata : Option < HashMap < String , String > > ,
171
+ }
172
+
165
173
/// Insert a vector into a collection
166
174
async fn insert_into_collection (
167
- Path ( collection_name) : Path < String > ,
175
+ Path ( ( collection_name, embedding_id ) ) : Path < ( String , String ) > ,
168
176
Extension ( db) : DbExtension ,
169
- Json ( embedding ) : Json < Embedding > ,
177
+ Json ( embedding_data ) : Json < EmbeddingData > ,
170
178
) -> Result < StatusCode , HTTPError > {
171
179
tracing:: trace!( "Inserting into collection {collection_name}" ) ;
172
180
173
181
let mut db = db. write ( ) . await ;
174
182
183
+ let embedding = Embedding {
184
+ id : embedding_id,
185
+ vector : embedding_data. vector ,
186
+ metadata : embedding_data. metadata ,
187
+ } ;
175
188
let insert_result = db. insert_into_collection ( & collection_name, embedding) ;
176
189
drop ( db) ;
177
190
@@ -263,10 +276,6 @@ async fn get_embedding(
263
276
) -> Result < Json < Embedding > , HTTPError > {
264
277
tracing:: trace!( "Getting {embedding_id} from collection {collection_name}" ) ;
265
278
266
- if embedding_id. len ( ) == 0 {
267
- return Err ( HTTPError :: new ( "Embedding identifier empty" ) . with_status ( StatusCode :: BAD_REQUEST ) ) ;
268
- }
269
-
270
279
let db = db. read ( ) . await ;
271
280
let collection = db
272
281
. get_collection ( & collection_name)
0 commit comments