use bigrag::types::CreateCollectionBody;
use bigrag::{BigRag, FileInput};
#[tokio::main]
async fn main() -> Result<(), bigrag::BigRagError> {
let client = BigRag::from_env()?;
client
.collections()
.create(CreateCollectionBody {
name: "upload_test".into(),
..Default::default()
})
.await?;
let doc = client
.documents()
.upload("upload_test", "README.md", None)
.await?;
println!("From path: {} ({})", doc.filename, doc.status);
let content = b"# Hello\n\nThis is a test document.".to_vec();
let doc = client
.documents()
.upload("upload_test", (content, "hello.md"), None)
.await?;
println!("From bytes: {} ({})", doc.filename, doc.status);
let meta = serde_json::json!({"department": "engineering", "priority": "high"});
let doc = client
.documents()
.upload("upload_test", "Cargo.toml", Some(meta))
.await?;
println!("With metadata: {} ({})", doc.filename, doc.status);
let files = vec![
FileInput::from("README.md"),
FileInput::Bytes {
data: b"Another doc".to_vec(),
name: "another.txt".into(),
},
];
let batch = client
.documents()
.batch_upload("upload_test", files, None)
.await?;
println!("Batch uploaded: {} documents", batch.total);
let col = client.collection("upload_test");
let docs = col.list_documents(None).await?;
println!("\nTotal documents in collection: {}", docs.total);
client.collections().delete("upload_test").await?;
println!("Cleaned up.");
Ok(())
}