txtai AI Framework
repository·master·Indexed 11 days ago
https://github.com/neuml/txtaiAn all-in-one AI framework for semantic search, LLM orchestration, and language model workflows. Built on an embeddings database, it supports vector search, RAG, autonomous agents via smolagents, and multimodal indexing for text, audio, images, and video. It provides Web and Model Context Protocol (MCP) APIs with bindings for JavaScript, Java, Rust, and Go.
What's inside txtai
- txtai is an all-in-one AI framework designed for semantic search, LLM orchestration, and language model workflows. It is built on a core embeddings database that combines vector indexes (both sparse and dense), graph networks, and relational databases. This architecture allows it to function as both a high-performance vector search engine and a knowledge source for LLM applications like Retrieval Augmented Generation (RAG).
Overview of txtai capabilities
mastertxtai is an all-in-one AI framework designed for semantic search, LLM orchestration, and language model workflows. Its core is an embeddings database that combines vector indexes (sparse and dense), graph networks, and relational databases.
Key Features:
- Vector Search: Supports SQL, object storage, topic modeling, graph analysis, and multimodal indexing.
- Multimodal Embeddings: Create embeddings for text, documents, audio, images, and video.
- LLM Pipelines: Powered by language models for tasks like question-answering, labeling, transcription, translation, and summarization.
- Workflows: Join pipelines together to aggregate business logic into microservices or multi-model workflows.
- Agents: Connect embeddings, pipelines, and workflows to solve complex problems autonomously.
- APIs: Provides Web and Model Context Protocol (MCP) APIs with bindings for JavaScript, Java, Rust, and Go.
txtai API Language Bindings and Compatibility
masterThe txtai API is accessible through several official language bindings and standard protocols:
Language Bindings:
- Python
- JavaScript
- Java
- Rust
- Go
Compatibility:
- OpenAI-compatible: Can be used with standard OpenAI client libraries.
- Model Context Protocol (MCP): Supports MCP endpoints.
Use the Tokenizer pipeline for keyword indexing
masterThe
Tokenizerpipeline splits text into individual tokens, which is primarily used for keyword or term indexing.Important Note: This pipeline is intended for keyword indexing and is not designed for use with Transformers-based models, as those models use their own specialized tokenizers.
from txtai.pipeline import Tokenizer tokenizer = Tokenizer() result = tokenizer("text to tokenize")Key features of txtai
mastertxtai provides a comprehensive suite of AI capabilities:
- Vector Search: Supports SQL, object storage, topic modeling, graph analysis, and multimodal indexing.
- Multimodal Embeddings: Create embeddings for text, documents, audio, images, and video.
- LLM Pipelines: Run language model tasks including LLM prompts, question-answering, labeling, transcription, translation, and summarization.
- Workflows: Join multiple pipelines together to aggregate business logic, ranging from simple microservices to complex multi-model workflows.
- Agents: Intelligently connect embeddings, pipelines, workflows, and other agents to solve complex problems autonomously.
- APIs & Bindings: Provides Web and Model Context Protocol (MCP) APIs. Language bindings are available for JavaScript, Java, Rust, and Go.
- Deployment: Designed to run locally or scale out using container orchestration.
How semantic graphs work in txtai
masterEnabling a graph network adds a semantic graph at index time. txtai uses vector embeddings to automatically create relationships between nodes, but you can also specify them manually.
Manual Relationships
You can define relationships during the
indexcall in two ways:- By ID: Provide a list of target IDs.
- With Attributes: Provide a list of dictionaries containing the target
idand a relationshiptype(e.g.,MEMBER_OF).
Graph Analysis
Once indexed, you can interact with the graph using:
embeddings.graph.topics: Returns a mapping of discovered topics to associated IDs.embeddings.graph.centrality(): Returns the most central nodes in the index.
Graphs are persisted alongside the embeddings index during
saveandloadoperations.# Manual relationships by id embeddings.index([{"id": "0", "text": "...", "relationships": ["2"]}]) # Manual relationships with additional edge attributes embeddings.index([{"id": "0", "text": "...", "relationships": [ {"id": "2", "type": "MEMBER_OF"} ]}])Configure data merging (packing) in HFTrainer
masterFor
language-generationandlanguage-modelingtasks, themergeparameter controls how text is packed into chunks to improve training efficiency by reducing padding.Merge Options
concat(default): Text is split into chunks up tomaxlength. Data can be split across multiple chunks. This maximizes efficiency and is recommended for general masked language modeling.pack: Text is split into chunks up tomaxlength. Data is guaranteed to stay within the same chunk, though chunks may be smaller thanmaxlength. This is recommended for instruction/prompt fine-tuning to ensure complex logic isn't split.None: Disables merging entirely.
Implement Agentic RAG
masterUnlike standard Retrieval Augmented Generation (RAG) which performs a single vector search, Agentic RAG uses an agent to perform multiple iterations and potentially query multiple databases to reach a conclusion. This is useful for aggregating information from diverse sources to build complex reports.
To implement this, pass a detailed prompt (instruction) to the
Agentinstance, instructing it on how to use its available tools to research and format the output.researcher_prompt = """ You're an expert researcher looking to write a paper on {topic}. Search for websites, scientific papers and Wikipedia related to the topic. Write a report with summaries and references (with hyperlinks). Write the text as Markdown. """ # The agent will use its tools to fulfill the multi-step research instruction agent(researcher_prompt.format(topic="alien life"))Build Agent Teams
masterIn
txtai, agents can be used as tools for other agents. This allows you to build Agent Teams, where a primary agent delegates tasks to specialized sub-agents. Each sub-agent has its own reasoning engine and toolset.To create an agent team:
- Define specialized sub-agents (e.g., a
websearcheragent or awikimanagent). - Create a primary agent and pass the sub-agents into its
toolslist using a dictionary with atargetkey pointing to the sub-agent instance.
Sub-agent tool dictionary format:
name: The name the primary agent uses to refer to the tool.description: Instructions for the primary agent on when to use this sub-agent.target: The actualAgentinstance to be invoked.
from txtai import Agent, LLM llm = LLM("Qwen/Qwen3-4B-Instruct-2507") # Define specialized sub-agents websearcher = Agent(model=llm, tools=["websearch"]) wikiman = Agent( model=llm, tools=[{ "name": "wikipedia", "description": "Searches a Wikipedia database", "provider": "huggingface-hub", "container": "neuml/txtai-wikipedia" }] ) # Define the primary agent that uses the sub-agents as tools agent = Agent( model=llm, tools=[ { "name": "wikiman", "description": "Wikipedia has all the answers, I search Wikipedia and answer questions", "target": wikiman }, { "name": "websearcher", "description": "I run web searches, there is no answer a web search can't solve!", "target": websearcher } ], max_steps=10 ) agent("Research fundamental concepts about Signal Processing and build a comprehensive report.")- Define specialized sub-agents (e.g., a
Add middleware using Dependencies
masterTo add custom logic that executes with every request, use Dependencies. Dependencies function as middleware and are ideal for implementing custom authorization steps, authentication methods, or other request-processing logic that should run before the main application logic.
See the [API Authorization and Authentication](https://github.com/neuml/txtai/blob/master/examples/54_API_Authorization_and_Authentication.ipynb) notebook for a detailed implementation example.Query data using SQL and the `similar` clause
masterIf content storage is enabled, you can use SQL to combine similarity searches with structured filters. The
similarclause is the bridge between the similarity index and the relational database.Syntax:
similar("query", "number of candidates", "index", "weights")Argument Description queryNatural language query string number of candidatesNumber of candidate results to return. Should be larger than the desired LIMITto account for filters. Defaults to query limit for single filters, or 10x limit for multiple filters.indexTarget subindex name (if subindexes are enabled) weightsHybrid score weights (for sparse/dense indexes) Example:
SELECT id, text, score FROM txtai WHERE similar('feel good story')Explore LLM Orchestration and Agents
mastertxtai provides orchestration for Large Language Models (LLMs), including autonomous agents, Retrieval Augmented Generation (RAG), and complex task chains.
Agents
Agents in txtai connect embeddings, pipelines, and workflows to solve complex problems autonomously. They are built on top of the
smolagentsframework and support:- LLM Providers: Hugging Face, llama.cpp, and OpenAI/Claude/AWS Bedrock (via LiteLLM).
- Prompting Standards: Support for
agents.mdandskill.mdspecifications. - Toolkits: Access to the txtai agent toolkit for specialized tasks.
Retrieval Augmented Generation (RAG)
RAG reduces LLM hallucinations by providing a knowledge base as context (e.g., "chat with your data"). txtai supports:
- Standard RAG: Building pipelines with citations.
- Multi-source RAG: Retrieving context from Web, SQL, and other sources.
- GraphRAG: Deep graph search powered RAG using knowledge graphs.