Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

2.9 KB
Raw Blame
use crate::{
    OpensearchClient, Result, delete,
    retry::resend_on_lost_connection,
    upsert::{self, document::UpsertDocumentArgs, properties::IndexedProperty},
};

impl OpensearchClient {
    /// Inserts a document into the opensearch index
    #[tracing::instrument(skip(self))]
    pub async fn upsert_document(&self, upsert_document_args: &UpsertDocumentArgs) -> Result<()> {
        resend_on_lost_connection(|| {
            upsert::document::upsert_document(&self.inner, upsert_document_args, None)
        })
        .await
    }

    /// Upserts only the parent doc (no content chunks) into the opensearch index
    #[tracing::instrument(skip(self), err)]
    pub async fn upsert_parent_document(
        &self,
        upsert_document_args: &UpsertDocumentArgs,
        index_override: Option<&str>,
    ) -> Result<()> {
        resend_on_lost_connection(|| {
            upsert::document::upsert_parent_document(
                &self.inner,
                upsert_document_args,
                index_override,
            )
        })
        .await
    }

    /// Bulk upserts documents into the opensearch index
    #[tracing::instrument(skip(self, documents))]
    pub async fn bulk_upsert_documents(
        &self,
        documents: &[UpsertDocumentArgs],
        index_override: Option<&str>,
    ) -> Result<upsert::BulkUpsertResult> {
        resend_on_lost_connection(|| {
            upsert::document::bulk_upsert_documents(&self.inner, documents, index_override)
        })
        .await
    }

    /// Deletes a document from the opensearch document index
    #[tracing::instrument(skip(self))]
    pub async fn delete_document(
        &self,
        document_id: &str,
        index_override: Option<&str>,
    ) -> Result<()> {
        resend_on_lost_connection(|| {
            delete::document::delete_document_by_id(&self.inner, document_id, index_override)
        })
        .await
    }

    #[tracing::instrument(skip(self))]
    pub async fn update_document_metadata(
        &self,
        document_id: &str,
        document_name: &str,
    ) -> Result<()> {
        resend_on_lost_connection(|| {
            upsert::document::update_document_metadata(&self.inner, document_id, document_name)
        })
        .await
    }

    /// Refresh only the denormalized `properties` on an existing parent doc.
    #[tracing::instrument(skip(self, properties))]
    pub async fn update_document_properties(
        &self,
        document_id: &str,
        properties: &[IndexedProperty],
    ) -> Result<()> {
        resend_on_lost_connection(|| {
            upsert::document::update_document_properties(&self.inner, document_id, properties, None)
        })
        .await
    }

    #[tracing::instrument(skip(self))]
    pub async fn delete_documents_by_owner_id(&self, owner_id: &str) -> Result<()> {
        resend_on_lost_connection(|| {
            delete::document::delete_document_by_owner_id(&self.inner, owner_id)
        })
        .await
    }
}