44//! Batch document processing example.
55//!
66//! This example demonstrates how to efficiently process
7- //! multiple documents in batch mode using sessions .
7+ //! multiple documents in batch mode.
88//!
99//! # Usage
1010//!
1111//! ```bash
1212//! cargo run --example batch_processing
1313//! ```
1414
15- use vectorless:: client:: { EngineBuilder , IndexContext } ;
15+ use vectorless:: client:: { EngineBuilder , IndexContext , QueryContext } ;
1616
1717#[ tokio:: main]
1818async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
1919 println ! ( "=== Batch Document Processing Example ===\n " ) ;
2020
21- // 1. Create engine and session
21+ // 1. Create engine
2222 println ! ( "Step 1: Setting up..." ) ;
2323 let engine = EngineBuilder :: new ( )
2424 . with_workspace ( "./workspace_batch_example" )
2525 . build ( )
2626 . await
2727 . map_err ( |e : vectorless:: BuildError | vectorless:: Error :: Config ( e. to_string ( ) ) ) ?;
2828
29- let session = engine. session ( ) . await ;
30- println ! ( " ✓ Session created: {}\n " , session. id( ) ) ;
29+ println ! ( " ✓ Engine created\n " ) ;
3130
3231 // 2. Create sample documents
3332 println ! ( "Step 2: Creating sample documents..." ) ;
@@ -1059,8 +1058,9 @@ Implement authentication for production.
10591058
10601059 for ( name, _) in & documents {
10611060 let path = temp_dir. path ( ) . join ( name) ;
1062- match session. index ( IndexContext :: from_path ( & path) ) . await {
1063- Ok ( doc_id) => {
1061+ match engine. index ( IndexContext :: from_path ( & path) ) . await {
1062+ Ok ( result) => {
1063+ let doc_id = result. doc_id ( ) . unwrap ( ) . to_string ( ) ;
10641064 doc_ids. push ( doc_id) ;
10651065 }
10661066 Err ( e) => {
@@ -1077,14 +1077,13 @@ Implement authentication for production.
10771077 ) ;
10781078 println ! ( ) ;
10791079
1080- // 4. Show session stats
1081- println ! ( "Step 4: Session statistics :" ) ;
1082- let stats = session . stats ( ) ;
1080+ // 4. Show indexed documents
1081+ println ! ( "Step 4: Indexed documents :" ) ;
1082+ let docs = engine . list ( ) . await ? ;
10831083 println ! (
1084- " - Documents in session : {}" ,
1085- session . list_documents ( ) . len( )
1084+ " - Documents indexed : {}" ,
1085+ docs . len( )
10861086 ) ;
1087- println ! ( " - Queries: {}" , stats. query_count. get( ) ) ;
10881087 println ! ( ) ;
10891088
10901089 // 5. Batch query with progress
@@ -1106,16 +1105,22 @@ Implement authentication for production.
11061105 let mut success_count = 0 ;
11071106
11081107 for query in & queries {
1109- match session. query_all ( query) . await {
1110- Ok ( results) => {
1111- if !results. is_empty ( ) {
1112- success_count += 1 ;
1108+ // Query against each indexed document, count as success if any returns content
1109+ let mut found = false ;
1110+ for doc_id in & doc_ids {
1111+ match engine. query ( QueryContext :: new ( * query) . with_doc_id ( doc_id) ) . await {
1112+ Ok ( result) => {
1113+ if !result. content . is_empty ( ) {
1114+ found = true ;
1115+ break ;
1116+ }
11131117 }
1114- }
1115- Err ( e) => {
1116- eprintln ! ( " ✗ Query failed: {}" , e) ;
1118+ Err ( _) => { }
11171119 }
11181120 }
1121+ if found {
1122+ success_count += 1 ;
1123+ }
11191124 }
11201125
11211126 let elapsed = start. elapsed ( ) ;
@@ -1132,16 +1137,8 @@ Implement authentication for production.
11321137
11331138 // 6. Final statistics
11341139 println ! ( "Step 6: Final statistics:" ) ;
1135- let stats = session. stats ( ) ;
1136- println ! ( " - Total documents: {}" , session. list_documents( ) . len( ) ) ;
1137- println ! ( " - Total queries: {}" , stats. query_count. get( ) ) ;
1138- println ! ( " - Cache hits: {}" , stats. cache_hits. get( ) ) ;
1139- println ! ( " - Cache misses: {}" , stats. cache_misses. get( ) ) ;
1140- println ! ( " - Cache hit rate: {:.1}%" , stats. cache_hit_rate( ) * 100.0 ) ;
1141- if let Some ( avg_time) = stats. avg_query_time ( ) {
1142- println ! ( " - Avg query time: {:?}" , avg_time) ;
1143- }
1144- println ! ( " - Session age: {:?}" , session. age( ) ) ;
1140+ let docs = engine. list ( ) . await ?;
1141+ println ! ( " - Total documents: {}" , docs. len( ) ) ;
11451142 println ! ( ) ;
11461143
11471144 // 7. Cleanup
0 commit comments