@@ -129,7 +129,9 @@ pub struct Collection {
129129 exists,
130130 archive,
131131 upsert_directory,
132- upsert_file
132+ upsert_file,
133+ generate_er_diagram,
134+ get_pipeline_status
133135) ]
134136impl Collection {
135137/// Creates a new [Collection]
@@ -259,25 +261,6 @@ impl Collection {
259261}
260262
261263/// Adds a new [Pipeline] to the [Collection]
262- ///
263- /// # Arguments
264- ///
265- /// * `pipeline` - The [Pipeline] to add.
266- ///
267- /// # Example
268- ///
269- /// ```
270- /// use pgml::{Collection, Pipeline, Model, Splitter};
271- ///
272- /// async fn example() -> anyhow::Result<()> {
273- /// let model = Model::new(None, None, None);
274- /// let splitter = Splitter::new(None, None);
275- /// let mut pipeline = Pipeline::new("my_pipeline", None, None, None);
276- /// let mut collection = Collection::new("my_collection", None);
277- /// collection.add_pipeline(&mut pipeline).await?;
278- /// Ok(())
279- /// }
280- /// ```
281264#[ instrument( skip( self ) ) ]
282265pub async fn add_pipeline ( & mut self , pipeline : & mut Pipeline ) -> anyhow:: Result < ( ) > {
283266// The flow for this function:
@@ -322,23 +305,6 @@ impl Collection {
322305}
323306
324307/// Removes a [Pipeline] from the [Collection]
325- ///
326- /// # Arguments
327- ///
328- /// * `pipeline` - The [Pipeline] to remove.
329- ///
330- /// # Example
331- ///
332- /// ```
333- /// use pgml::{Collection, Pipeline};
334- ///
335- /// async fn example() -> anyhow::Result<()> {
336- /// let mut pipeline = Pipeline::new("my_pipeline", None, None, None);
337- /// let mut collection = Collection::new("my_collection", None);
338- /// collection.remove_pipeline(&mut pipeline).await?;
339- /// Ok(())
340- /// }
341- /// ```
342308#[ instrument( skip( self ) ) ]
343309pub async fn remove_pipeline ( & mut self , pipeline : & Pipeline ) -> anyhow:: Result < ( ) > {
344310// The flow for this function:
@@ -368,29 +334,12 @@ impl Collection {
368334}
369335
370336/// Enables a [Pipeline] on the [Collection]
371- ///
372- /// # Arguments
373- ///
374- /// * `pipeline` - The [Pipeline] to enable
375- ///
376- /// # Example
377- ///
378- /// ```
379- /// use pgml::{Collection, Pipeline};
380- ///
381- /// async fn example() -> anyhow::Result<()> {
382- /// let pipeline = Pipeline::new("my_pipeline", None, None, None);
383- /// let collection = Collection::new("my_collection", None);
384- /// collection.enable_pipeline(&pipeline).await?;
385- /// Ok(())
386- /// }
387- /// ```
388337#[ instrument( skip( self ) ) ]
389338pub async fn enable_pipeline ( & mut self , pipeline : & mut Pipeline ) -> anyhow:: Result < ( ) > {
390339// The flow for this function:
391340// 1. Set ACTIVE = TRUE for the pipeline in collection.pipelines
392341// 2. Resync the pipeline
393- //TOOD : Review this pattern
342+ //TODO : Review this pattern
394343self . verify_in_database ( false ) . await ?;
395344let project_info =& self . database_data . as_ref ( ) . unwrap ( ) . project_info ;
396345let pool =get_or_initialize_pool ( & self . database_url ) . await ?;
@@ -407,23 +356,6 @@ impl Collection {
407356}
408357
409358/// Disables a [Pipeline] on the [Collection]
410- ///
411- /// # Arguments
412- ///
413- /// * `pipeline` - The [Pipeline] to disable
414- ///
415- /// # Example
416- ///
417- /// ```
418- /// use pgml::{Collection, Pipeline};
419- ///
420- /// async fn example() -> anyhow::Result<()> {
421- /// let pipeline = Pipeline::new("my_pipeline", None, None, None);
422- /// let collection = Collection::new("my_collection", None);
423- /// collection.disable_pipeline(&pipeline).await?;
424- /// Ok(())
425- /// }
426- /// ```
427359#[ instrument( skip( self ) ) ]
428360pub async fn disable_pipeline ( & self , pipeline : & Pipeline ) -> anyhow:: Result < ( ) > {
429361// The flow for this function:
@@ -459,27 +391,6 @@ impl Collection {
459391}
460392
461393/// Upserts documents into the database
462- ///
463- /// # Arguments
464- ///
465- /// * `documents` - A vector of documents to upsert
466- /// * `strict` - Whether to throw an error if keys: `id` or `text` are missing from any documents
467- ///
468- /// # Example
469- ///
470- /// ```
471- /// use pgml::Collection;
472- ///
473- /// async fn example() -> anyhow::Result<()> {
474- /// let mut collection = Collection::new("my_collection", None);
475- /// let documents = vec![
476- /// serde_json::json!({"id": 1, "text": "hello world"}).into(),
477- /// serde_json::json!({"id": 2, "text": "hello world"}).into(),
478- /// ];
479- /// collection.upsert_documents(documents, None).await?;
480- /// Ok(())
481- /// }
482- /// ```
483394#[ instrument( skip( self , documents) ) ]
484395pub async fn upsert_documents (
485396& mut self ,
@@ -647,21 +558,6 @@ impl Collection {
647558}
648559
649560/// Gets the documents on a [Collection]
650- ///
651- /// # Arguments
652- ///
653- /// * `args` - The filters and options to apply to the query
654- ///
655- /// # Example
656- ///
657- /// ```
658- /// use pgml::Collection;
659- ///
660- /// async fn example() -> anyhow::Result<()> {
661- /// let mut collection = Collection::new("my_collection", None);
662- /// let documents = collection.get_documents(None).await?;
663- /// Ok(())
664- /// }
665561#[ instrument( skip( self ) ) ]
666562pub async fn get_documents ( & self , args : Option < Json > ) -> anyhow:: Result < Vec < Json > > {
667563let pool =get_or_initialize_pool ( & self . database_url ) . await ?;
@@ -721,25 +617,6 @@ impl Collection {
721617}
722618
723619/// Deletes documents in a [Collection]
724- ///
725- /// # Arguments
726- ///
727- /// * `filter` - The filters to apply
728- ///
729- /// # Example
730- ///
731- /// ```
732- /// use pgml::Collection;
733- ///
734- /// async fn example() -> anyhow::Result<()> {
735- /// let mut collection = Collection::new("my_collection", None);
736- /// let documents = collection.delete_documents(serde_json::json!({
737- /// "id": {
738- /// "eq": 1
739- /// }
740- /// }).into()).await?;
741- /// Ok(())
742- /// }
743620#[ instrument( skip( self ) ) ]
744621pub async fn delete_documents ( & self , filter : Json ) -> anyhow:: Result < ( ) > {
745622let pool =get_or_initialize_pool ( & self . database_url ) . await ?;
@@ -832,25 +709,6 @@ impl Collection {
832709}
833710
834711/// Performs vector search on the [Collection]
835- ///
836- /// # Arguments
837- ///
838- /// * `query` - The query to search for
839- /// * `pipeline` - The [Pipeline] used for the search
840- /// * `query_paramaters` - The query parameters passed to the model for search
841- ///
842- /// # Example
843- ///
844- /// ```
845- /// use pgml::{Collection, Pipeline};
846- ///
847- /// async fn example() -> anyhow::Result<()> {
848- /// let mut collection = Collection::new("my_collection", None);
849- /// let mut pipeline = Pipeline::new("my_pipeline", None, None, None);
850- /// let results = collection.vector_search("Query", &mut pipeline, None, None).await?;
851- /// Ok(())
852- /// }
853- /// ```
854712#[ instrument( skip( self ) ) ]
855713#[ allow( clippy:: type_complexity) ]
856714pub async fn vector_search (
@@ -956,18 +814,6 @@ impl Collection {
956814}
957815
958816/// Gets all pipelines for the [Collection]
959- ///
960- /// # Example
961- ///
962- /// ```
963- /// use pgml::Collection;
964- ///
965- /// async fn example() -> anyhow::Result<()> {
966- /// let mut collection = Collection::new("my_collection", None);
967- /// let pipelines = collection.get_pipelines().await?;
968- /// Ok(())
969- /// }
970- /// ```
971817#[ instrument( skip( self ) ) ]
972818pub async fn get_pipelines ( & mut self ) -> anyhow:: Result < Vec < Pipeline > > {
973819self . verify_in_database ( false ) . await ?;
@@ -982,18 +828,6 @@ impl Collection {
982828}
983829
984830/// Gets a [Pipeline] by name
985- ///
986- /// # Example
987- ///
988- /// ```
989- /// use pgml::Collection;
990- ///
991- /// async fn example() -> anyhow::Result<()> {
992- /// let mut collection = Collection::new("my_collection", None);
993- /// let pipeline = collection.get_pipeline("my_pipeline").await?;
994- /// Ok(())
995- /// }
996- /// ```
997831#[ instrument( skip( self ) ) ]
998832pub async fn get_pipeline ( & mut self , name : & str ) -> anyhow:: Result < Pipeline > {
999833self . verify_in_database ( false ) . await ?;
@@ -1009,18 +843,6 @@ impl Collection {
1009843}
1010844
1011845/// Check if the [Collection] exists in the database
1012- ///
1013- /// # Example
1014- ///
1015- /// ```
1016- /// use pgml::Collection;
1017- ///
1018- /// async fn example() -> anyhow::Result<()> {
1019- /// let collection = Collection::new("my_collection", None);
1020- /// let exists = collection.exists().await?;
1021- /// Ok(())
1022- /// }
1023- /// ```
1024846#[ instrument( skip( self ) ) ]
1025847pub async fn exists ( & self ) -> anyhow:: Result < bool > {
1026848let pool =get_or_initialize_pool ( & self . database_url ) . await ?;
@@ -1108,13 +930,15 @@ impl Collection {
1108930Ok ( ( ) )
1109931}
1110932
933+ #[ instrument( skip( self ) ) ]
1111934pub async fn get_pipeline_status ( & mut self , pipeline : & mut Pipeline ) -> anyhow:: Result < Json > {
1112935self . verify_in_database ( false ) . await ?;
1113936let project_info =& self . database_data . as_ref ( ) . unwrap ( ) . project_info ;
1114937let pool =get_or_initialize_pool ( & self . database_url ) . await ?;
1115938 pipeline. get_status ( project_info, & pool) . await
1116939}
1117940
941+ #[ instrument( skip( self ) ) ]
1118942pub async fn generate_er_diagram ( & mut self , pipeline : & mut Pipeline ) -> anyhow:: Result < String > {
1119943self . verify_in_database ( false ) . await ?;
1120944let project_info =& self . database_data . as_ref ( ) . unwrap ( ) . project_info ;