ai.devant
Module ai.devant
API
Declarations
sumudunissanka/ai.devant
Overview
The ai.devant module provides APIs to interact with Devant by WSO2, enabling document chunking and loading documents from a directory in the format expected by the Devant Chunker. It integrates seamlessly with the ai module to provide a smooth workflow for processing AI documents using Devant AI services.
Key Features
- Load documents from a directory in the format expected by the Devant Chunker
- Chunk documents using the Devant AI service
- Seamless integration with the
aimodule for AI document processing workflows
Prerequisites
Before using this module in your Ballerina application, ensure you have the following:
- A valid Devant AI service URL
- An access token to authenticate with the Devant platform
Quickstart
To use the ai.devant module in your Ballerina application, follow these steps:
Step 1: Import the module
import ballerinax/ai.devant;
Step 2: Load the document
devant:BinaryDataLoader loader = check new ("./sample.pdf"); ai:Document|ai:Document[] docs = check loader.load();
Step 3: Chunk the documents using the Devant service
devant:Chunker chunker = new (serviceUrl, accessToken); if docs is ai:Document { ai:Chunk[] chunks = check chunker.chunk(docs); }
Classes
ai.devant: BinaryDataLoader
Loads documents as ai:BinaryDocument instances from a specified file or directory path.
This loader can handle either a single file or a directory containing multiple files.
Typically used in conjunction with devant:Chunker to split documents into chunks for processing.
Constructor
Creates a new BinaryDataLoader instance.
init (string path)- path string - The file or directory path to load documents from
load
Loads documents from the specified path.
ai.devant: Chunker
Splits documents loaded by the devant:BinaryDataLoader into smaller chunks
using the Devant AI service.
Constructor
Initializes a new Chunker instance.
init (string serviceUrl, string accessToken, int maxChunkSize, int maxOverlapSize, ChunkStrategy strategy, *ConnectionConfig connectionConfig)- serviceUrl string - The base URL of the Devant AI service endpoint
- accessToken string - The access token used to authenticate API requests
- maxChunkSize int 500 - The maximum number of characters allowed per chunk
- maxOverlapSize int 50 - The maximum number of characters to reuse from the end of the previous chunk when creating the next one
- strategy ChunkStrategy RECURSIVE - The strategy to use for chunking the document
- connectionConfig *ConnectionConfig - Additional HTTP connection configurations
chunk
Chunks the provided document.
Parameters
- document Document - The input document to be chunked
ai.devant: KnowledgeBase
Represents a Devant knowledge base for retrieving relevant chunks.
Constructor
Initializes a new KnowledgeBase instance.
init (string serviceUrl, ConnectKnowledgeBase knowledgeBaseAuthConfig, decimal minSimilarityThreshold, string? cohereRerankerApiKey, string? cohereRerankerModel, int rerankerTopN, *ConnectionConfig connectionConfig)- serviceUrl string -
- knowledgeBaseAuthConfig ConnectKnowledgeBase -
- minSimilarityThreshold decimal 0.7 - The minimum similarity score threshold for retrieved chunks (default: 0.0)
- cohereRerankerApiKey string? () - The API key for the Cohere reranker service; omit to disable reranking
- cohereRerankerModel string? () - The Cohere reranker model name to use
- rerankerTopN int 5 - The number of top results to return from the reranker (default: 5)
- connectionConfig *ConnectionConfig - Additional HTTP connection configurations
ingest
Ingests documents into the Devant knowledge base.
Return Type
- Error? - An
ai:Errorsince ingestion is not supported by the Devant retrieve API
retrieve
function retrieve(string query, int maxLimit, MetadataFilters? filters) returns QueryMatch[]|ErrorRetrieves relevant chunks for the given query using Devant.
Parameters
- query string - The text query to search for
- maxLimit int (default 10) - The maximum number of items to return
- filters MetadataFilters? (default ()) - Optional metadata filters to apply during retrieval
Return Type
- QueryMatch[]|Error - An array of matching chunks with similarity scores, or an
ai:Errorif retrieval fails
deleteByFilter
function deleteByFilter(MetadataFilters filters) returns Error?Deletes chunks that match the given metadata filters.
Parameters
- filters MetadataFilters - The metadata filters used to identify which chunks to delete
Return Type
- Error? - An
ai:Errorsince deletion is not supported by the Devant retrieve API
Enums
ai.devant: ChunkStrategy
Specifies the strategy to split text into chunks.
Members
Records
ai.devant: AccessTokenConfig
Configuration for bearer token authentication.
Fields
- accessToken string - The bearer access token used to authenticate API requests
ai.devant: AzureOpenAIEmbeddingModel
Configuration for an Azure OpenAI embedding model.
Fields
- modelId string - The Azure OpenAI model deployment ID
- baseUrl string - The Azure OpenAI base URL
- apiKey string - The Azure OpenAI API key
- apiVersion string - The Azure OpenAI API version
ai.devant: ChromaVectorStore
Configuration for a Chroma vector store.
Fields
- host string - The Chroma server host
- port int - The Chroma server port
- collectionName string - The name of the Chroma collection
ai.devant: ConnectKnowledgeBase
Configuration for connecting to an existing Devant knowledge base.
Fields
- auth BearerTokenConfig|OAuth2ClientCredentialsGrantConfig - Authentication configuration: either bearer token or OAuth2 client credentials
- timeout? decimal - The HTTP client timeout in seconds (optional)
ai.devant: CreateKnowledgeBase
Configuration for creating a new Devant knowledge base.
Fields
- knowledgeBaseName string -
- vectorStore DevantVectorStore - The vector store to use for the knowledge base
- embeddingModel DevantEmbeddingModel - The embedding model to use for the knowledge base
- chunkStrategy? string - The chunking strategy to apply when ingesting documents
ai.devant: MistralEmbeddingModel
Configuration for a Mistral embedding model.
Fields
- model string - The Mistral embedding model name
- apiKey string - The Mistral API key
ai.devant: OAuth2Config
Configuration for OAuth2 client credentials authentication.
Fields
- tokenUrl string - The OAuth2 token endpoint URL
- clientId string - The OAuth2 client ID
- clientSecret string - The OAuth2 client secret
- scopes? string[] - The OAuth2 scopes to request (optional)
ai.devant: OpenAIEmbeddingModel
Configuration for an OpenAI embedding model.
Fields
- model string - The OpenAI embedding model name
- accessToken string - The OpenAI access token
ai.devant: PineconeVectorStore
Configuration for a Pinecone vector store.
Fields
- apiKey string - The Pinecone API key
- indexName string - The name of the Pinecone index
ai.devant: PostgreSQLVectorStore
Configuration for a PostgreSQL vector store.
Fields
- host string - The PostgreSQL server host
- port int - The PostgreSQL server port
- user string - The PostgreSQL username
- password string - The PostgreSQL password
- database string - The PostgreSQL database name
- tableName string - The table used to store vectors
ai.devant: WeaviateVectorStore
Configuration for a Weaviate vector store.
Fields
- clusterRestUrl string - The Weaviate cluster REST URL
- apiKey string - The Weaviate API key
- collectionName string - The name of the Weaviate collection
Errors
ai.devant: Error
Defines the common error type for the module.
Union types
ai.devant: DevantVectorStore
DevantVectorStore
Union of all supported Devant vector store configurations.
ai.devant: DevantEmbeddingModel
DevantEmbeddingModel
Union of all supported Devant embedding model configurations.
Import
import sumudunissanka/ai.devant;Metadata
Released date: 1 day ago
Version: 1.0.10
License: Apache-2.0
Compatibility
Platform: any
Ballerina version: 2201.12.0
GraalVM compatible: Yes
Pull count
Total: 7
Current verison: 2
Weekly downloads
Keywords
Vendor/WSO2
Area/AI & Machine Learning
Type/Connector
Contributors