Skip to main content

CollectionsApi

Struct CollectionsApi 

Source
pub struct CollectionsApi { /* private fields */ }
Expand description

Collections API client.

Implementations§

Source§

impl CollectionsApi

Source

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);
Source

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?;
Source

pub async fn get(&self, collection_id: impl AsRef<str>) -> Result<Collection>

Get a collection by ID.

Source

pub async fn update( &self, collection_id: impl AsRef<str>, request: UpdateCollectionRequest, ) -> Result<Collection>

Update a collection.

Source

pub async fn upsert_document( &self, collection_id: impl AsRef<str>, document: Document, ) -> Result<Document>

Add or replace a document by ID.

Source

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.

Source

pub async fn batch_get_documents( &self, collection_id: impl AsRef<str>, request: BatchGetDocumentsRequest, ) -> Result<DocumentListResponse>

Get multiple documents by IDs.

Source

pub async fn search_documents( &self, request: SearchRequest, ) -> Result<SearchResponse>

Search documents across all collections.

Source

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);
}
Source

pub async fn list_with_options( &self, limit: Option<u32>, next_token: Option<&str>, ) -> Result<CollectionListResponse>

List collections with pagination options.

Source

pub async fn delete(&self, collection_id: impl AsRef<str>) -> Result<()>

Delete a collection.

Source

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);
}
Source

pub async fn add_document( &self, collection_id: impl AsRef<str>, document: Document, ) -> Result<String>

Add a single document to a collection.

Source

pub async fn list_documents( &self, collection_id: impl AsRef<str>, ) -> Result<DocumentListResponse>

List documents in a collection.

Source

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.

Source

pub async fn get_document( &self, collection_id: impl AsRef<str>, document_id: impl AsRef<str>, ) -> Result<Document>

Get a document by ID.

Source

pub async fn delete_document( &self, collection_id: impl AsRef<str>, document_id: impl AsRef<str>, ) -> Result<()>

Delete a document from a collection.

Source

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);
}
Source

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

Source§

fn clone(&self) -> CollectionsApi

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CollectionsApi

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more