Kalosm Language
Language processing utilities for the Kalosm framework.
The language part of Kalosm has a few core parts:
- Models: Text generation and embedding models
- Context: Document collection, format support, search and chunking
- Integrations: SurrealDB, Serper, and other integrations
Text Generation Models
Model and ModelExt are the core traits for text generation models. Any model that implements these traits can be used with Kalosm.
The simplest way to use a model is to create a llama model and call stream_text on it:
use *;
async
Tasks
You can define a Task with a description then run it with an input. The task will cache the description to repeated calls faster. Tasks work with chat models.
use *;
async
Structured Generation
Structured generation gives you more control over the output of the text generation. You can derive a parser for your data to easily get structured data out of an LLM:
use *;
Then you can generate text that works with the parser in a Task:
# use *;
# use Arc;
async
Embedding Models
Embedder and EmbedderExt are the core traits for text embedding models. Any model that implements these traits can be used with Kalosm.
The simplest way to use an embedding model is to create a bert model and call embed on it. The Embedding you get back represents the meaning of the text in a numerical format:
use *;
async
Context
Gathering context is a key part of building LLM applications. Providing the right context to the model makes the output more relevant and useful. It can also help to prevent hallucinations.
Kalosm provides tools to generate gather, and process context from a variety of sources.
Gathering context
Kalosm provides utilities for collecting context from a variety of sources:
- Local files (.txt, .md, .html, .docx, .pdf)
- RSS feeds
- Websites
- Search engines
- Microphone input and audio input through whisper transcriptions
Each of these sources implements either IntoDocument or IntoDocuments to convert the data into a Document with the contents and metadata about the document.
use *;
use TryFrom;
use PathBuf;
async
Chunking context
After you have gathered context, it is often useful to chunk it into smaller pieces for search. Kalosm provides utilities for chunking context into documents, sentences, paragraphs, or semantic chunks. Kalosm will embed each chunk as it splits the document into smaller pieces. One of the most powerful chunker is the semantic chunker, which lets you chunk documents into semantically similar chunks without explicitly setting the size of the chunks:
use *;
async
Embedding-powered search
After you have chunked your context, you can use the embeddings for search or retrieval augmented generation. Embedding-based search lets you find documents that are semantically similar to a specific word or phrase even if no words are an exact match:
use *;
use ;
async