Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Neuml Txtai Console

From Leeroopedia


Knowledge Sources
Domains CLI, User_Interface
Last Updated 2026-02-09 17:00 GMT

Overview

Console is an interactive REPL command-line interface for querying txtai embeddings indexes and applications, with rich table output and token highlighting.

Description

The Console class inherits from Python's cmd.Cmd and provides an interactive read-eval-print loop for txtai. It supports loading both embeddings indexes and full YAML-configured applications, running search queries with tabular output via the Rich library, and executing workflows. The console includes dot-commands for configuration inspection (.config), result limit adjustment (.limit), token highlight coloring for explain queries (.highlight), index loading (.load), and workflow execution (.workflow). Any unrecognized input is treated as a search query by default.

Usage

Use Console for interactive exploration and debugging of txtai indexes and applications. It is particularly useful during development for testing search queries, inspecting index configuration, and verifying workflow behavior without writing application code.

Code Reference

Source Location

Signature

class Console(Cmd):
    def __init__(self, path=None):
        """
        Creates a new command line console.

        Args:
            path: path to initial configuration, if any
        """

Import

from txtai.console import Console

Key Methods

Method Description
preloop() Called before the REPL starts. Prints the welcome message and loads the initial configuration path, if provided.
default(line) Default event handler for all input. Routes commands starting with a dot (.config, .highlight, .limit, .load, .workflow) to their handlers; everything else is treated as a search query.
config() Prints the current application configuration to the console.
highlight(command) Sets the highlight color for explain query token visualization. Defaults to #ffff00 (yellow).
limit(command) Sets the maximum number of search results to display. Defaults to 10.
load(path) Loads a txtai index or YAML application configuration. YAML files are loaded as Application instances; all other paths are loaded as Embeddings indexes.
search(query) Runs a search (or explain, if highlighting is enabled) and displays results in a Rich-formatted table with styled columns.
workflow(command) Executes a named workflow with arguments when the loaded app is an Application instance.

Dot Commands

Command Description
.config Displays the current application configuration.
.highlight [color] Sets token highlight color for explain queries. Default: #ffff00.
.limit [n] Sets the maximum number of results. Default: 10.
.load path Loads an embeddings index or YAML application from the given path.
.workflow name arg1 arg2 ... Runs a named workflow with the provided arguments.
(any other text) Treated as a search query against the loaded index or application.

I/O Contract

Inputs

Name Type Required Description
path str No Path to an embeddings index directory or YAML application configuration file to load on startup.
line str Yes (interactive) User input from the REPL prompt. Dot-commands are routed to specific handlers; all other input is executed as a search query.

Outputs

Name Type Description
console output Rich Table Search results displayed as a formatted table in the terminal. Columns are derived from the result schema (id, score, text, etc.). When highlighting is enabled, matching tokens are shown with color formatting.

Usage Examples

Basic Usage

from txtai.console import Console

# Launch console with an existing embeddings index
console = Console(path="/path/to/embeddings/index")
console.cmdloop()

# Interactive session:
# >>> machine learning algorithms
# (displays search results table)
# >>> .limit 20
# Set limit to 20
# >>> .config
# (displays index configuration)

Loading an Application

from txtai.console import Console

# Launch console with a YAML application
console = Console(path="/path/to/app.yml")
console.cmdloop()

# Interactive session:
# >>> .workflow summary "Text to summarize goes here"
# (runs the summary workflow and displays results)
# >>> search query for documents
# (searches the application's embeddings index)

Command Line Launch

# Launch the txtai console from the command line
python -m txtai.console /path/to/index

# Or with a YAML application
python -m txtai.console /path/to/app.yml

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment