pub struct CollectionsApi { /* private fields */ }Expand description
Collections API client.
Implementations§
Source§impl CollectionsApi
impl CollectionsApi
Sourcepub async fn create(
&self,
request: CreateCollectionRequest,
) -> Result<Collection>
pub async fn create( &self, request: CreateCollectionRequest, ) -> Result<Collection>
Create a new collection.
§Example
use xai_rust::{XaiClient, CreateCollectionRequest};
let client = XaiClient::from_env()?;
let request = CreateCollectionRequest::new("my-documents")
.description("A collection of important documents");
let collection = client.collections().create(request).await?;
println!("Created: {}", collection.id);Sourcepub async fn create_named(&self, name: impl Into<String>) -> Result<Collection>
pub async fn create_named(&self, name: impl Into<String>) -> Result<Collection>
Create a collection with just a name.
§Example
use xai_rust::XaiClient;
let client = XaiClient::from_env()?;
let collection = client.collections().create_named("my-docs").await?;Sourcepub async fn get(&self, collection_id: impl AsRef<str>) -> Result<Collection>
pub async fn get(&self, collection_id: impl AsRef<str>) -> Result<Collection>
Get a collection by ID.
Sourcepub async fn update(
&self,
collection_id: impl AsRef<str>,
request: UpdateCollectionRequest,
) -> Result<Collection>
pub async fn update( &self, collection_id: impl AsRef<str>, request: UpdateCollectionRequest, ) -> Result<Collection>
Update a collection.
Sourcepub async fn upsert_document(
&self,
collection_id: impl AsRef<str>,
document: Document,
) -> Result<Document>
pub async fn upsert_document( &self, collection_id: impl AsRef<str>, document: Document, ) -> Result<Document>
Add or replace a document by ID.
Sourcepub async fn add_document_by_id(
&self,
collection_id: impl AsRef<str>,
document_id: impl AsRef<str>,
document: Document,
) -> Result<Document>
pub async fn add_document_by_id( &self, collection_id: impl AsRef<str>, document_id: impl AsRef<str>, document: Document, ) -> Result<Document>
Add or replace a document by explicit document ID.
Sourcepub async fn batch_get_documents(
&self,
collection_id: impl AsRef<str>,
request: BatchGetDocumentsRequest,
) -> Result<DocumentListResponse>
pub async fn batch_get_documents( &self, collection_id: impl AsRef<str>, request: BatchGetDocumentsRequest, ) -> Result<DocumentListResponse>
Get multiple documents by IDs.
Sourcepub async fn search_documents(
&self,
request: SearchRequest,
) -> Result<SearchResponse>
pub async fn search_documents( &self, request: SearchRequest, ) -> Result<SearchResponse>
Search documents across all collections.
Sourcepub async fn list(&self) -> Result<CollectionListResponse>
pub async fn list(&self) -> Result<CollectionListResponse>
List all collections.
§Example
use xai_rust::XaiClient;
let client = XaiClient::from_env()?;
let response = client.collections().list().await?;
for collection in response.data {
println!("{}: {} documents", collection.name, collection.document_count);
}Sourcepub async fn list_with_options(
&self,
limit: Option<u32>,
next_token: Option<&str>,
) -> Result<CollectionListResponse>
pub async fn list_with_options( &self, limit: Option<u32>, next_token: Option<&str>, ) -> Result<CollectionListResponse>
List collections with pagination options.
Sourcepub async fn add_documents(
&self,
collection_id: impl AsRef<str>,
documents: Vec<Document>,
) -> Result<AddDocumentsResponse>
pub async fn add_documents( &self, collection_id: impl AsRef<str>, documents: Vec<Document>, ) -> Result<AddDocumentsResponse>
Add documents to a collection.
§Example
use xai_rust::{XaiClient, Document};
let client = XaiClient::from_env()?;
let docs = vec![
Document::new("First document content"),
Document::new("Second document content"),
];
let response = client.collections()
.add_documents("collection-123", docs)
.await?;
for id in response.ids {
println!("Added document: {}", id);
}Sourcepub async fn add_document(
&self,
collection_id: impl AsRef<str>,
document: Document,
) -> Result<String>
pub async fn add_document( &self, collection_id: impl AsRef<str>, document: Document, ) -> Result<String>
Add a single document to a collection.
Sourcepub async fn list_documents(
&self,
collection_id: impl AsRef<str>,
) -> Result<DocumentListResponse>
pub async fn list_documents( &self, collection_id: impl AsRef<str>, ) -> Result<DocumentListResponse>
List documents in a collection.
Sourcepub async fn list_documents_with_options(
&self,
collection_id: impl AsRef<str>,
limit: Option<u32>,
next_token: Option<&str>,
) -> Result<DocumentListResponse>
pub async fn list_documents_with_options( &self, collection_id: impl AsRef<str>, limit: Option<u32>, next_token: Option<&str>, ) -> Result<DocumentListResponse>
List documents with pagination options.
Sourcepub async fn get_document(
&self,
collection_id: impl AsRef<str>,
document_id: impl AsRef<str>,
) -> Result<Document>
pub async fn get_document( &self, collection_id: impl AsRef<str>, document_id: impl AsRef<str>, ) -> Result<Document>
Get a document by ID.
Sourcepub async fn delete_document(
&self,
collection_id: impl AsRef<str>,
document_id: impl AsRef<str>,
) -> Result<()>
pub async fn delete_document( &self, collection_id: impl AsRef<str>, document_id: impl AsRef<str>, ) -> Result<()>
Delete a document from a collection.
Sourcepub async fn search(
&self,
collection_id: impl AsRef<str>,
request: SearchRequest,
) -> Result<SearchResponse>
pub async fn search( &self, collection_id: impl AsRef<str>, request: SearchRequest, ) -> Result<SearchResponse>
Search a collection.
§Example
use xai_rust::{XaiClient, SearchRequest};
let client = XaiClient::from_env()?;
let search = SearchRequest::new("machine learning")
.limit(10)
.score_threshold(0.5);
let response = client.collections()
.search("collection-123", search)
.await?;
for result in response.results {
println!("Score {}: {}", result.score, result.document.content);
}Sourcepub async fn search_query(
&self,
collection_id: impl AsRef<str>,
query: impl Into<String>,
) -> Result<SearchResponse>
pub async fn search_query( &self, collection_id: impl AsRef<str>, query: impl Into<String>, ) -> Result<SearchResponse>
Search a collection with a simple query string.
Trait Implementations§
Source§impl Clone for CollectionsApi
impl Clone for CollectionsApi
Source§fn clone(&self) -> CollectionsApi
fn clone(&self) -> CollectionsApi
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CollectionsApi
impl !RefUnwindSafe for CollectionsApi
impl Send for CollectionsApi
impl Sync for CollectionsApi
impl Unpin for CollectionsApi
impl UnsafeUnpin for CollectionsApi
impl !UnwindSafe for CollectionsApi
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more