@@ -25,10 +25,10 @@ pub fn handler() -> ApiRouter {
2525 . api_route ( "/:collection_name" , post ( query_collection) )
2626 . api_route ( "/:collection_name" , get ( get_collection_info) )
2727 . api_route ( "/:collection_name" , delete ( delete_collection) )
28- . api_route ( "/:collection_name/insert" , post ( insert_into_collection) )
2928 . api_route ( "/:collection_name/embeddings" , get ( get_embeddings) )
3029 . api_route ( "/:collection_name/embeddings" , post ( query_embeddings) )
3130 . api_route ( "/:collection_name/embeddings" , delete ( delete_embeddings) )
31+ . api_route ( "/:collection_name/embeddings/:embedding_id" , put ( insert_into_collection) )
3232 . api_route ( "/:collection_name/embeddings/:embedding_id" , get ( get_embedding) )
3333 . api_route ( "/:collection_name/embeddings/:embedding_id" , delete ( delete_embedding) ) ,
3434 )
@@ -162,16 +162,29 @@ async fn delete_collection(
162162 }
163163}
164164
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+
165173/// Insert a vector into a collection
166174async fn insert_into_collection (
167- Path ( collection_name) : Path < String > ,
175+ Path ( ( collection_name, embedding_id ) ) : Path < ( String , String ) > ,
168176 Extension ( db) : DbExtension ,
169- Json ( embedding ) : Json < Embedding > ,
177+ Json ( embedding_data ) : Json < EmbeddingData > ,
170178) -> Result < StatusCode , HTTPError > {
171179 tracing:: trace!( "Inserting into collection {collection_name}" ) ;
172180
173181 let mut db = db. write ( ) . await ;
174182
183+ let embedding = Embedding {
184+ id : embedding_id,
185+ vector : embedding_data. vector ,
186+ metadata : embedding_data. metadata ,
187+ } ;
175188 let insert_result = db. insert_into_collection ( & collection_name, embedding) ;
176189 drop ( db) ;
177190
@@ -263,10 +276,6 @@ async fn get_embedding(
263276) -> Result < Json < Embedding > , HTTPError > {
264277 tracing:: trace!( "Getting {embedding_id} from collection {collection_name}" ) ;
265278
266- if embedding_id. len ( ) == 0 {
267- return Err ( HTTPError :: new ( "Embedding identifier empty" ) . with_status ( StatusCode :: BAD_REQUEST ) ) ;
268- }
269-
270279 let db = db. read ( ) . await ;
271280 let collection = db
272281 . get_collection ( & collection_name)
0 commit comments