Insights from the txtai console
Debug, inspect and run txtai applications
txtai is an open-source platform for semantic search and workflows powered by language models. txtai supports building YAML-configured applications with a “build once, run anywhere” paradigm.
A number of articles cover txtai and are referenced below.
This article will demonstrate examples with the txtai console. The txtai console is built with the excellent Rich library.
Introducing the console
The first example is below.
The screencast above loads an existing index and runs a couple queries against the index. The console defaults to running queries if a command isn’t otherwise given.
The following commands are currently supported:
.config Shows the current configuration
.highlight Highlights tokens to explain why text matched
.limit Limits the number of query results to n
.load Loads an embeddings index or workflow
.workflow Runs a workflow
Note how in this example two queries are run feel good story
and climate change
. This is then followed by the same queries with result highlighting enabled. The highlighted text explains what tokens are most important in matching the query. This is important as txtai runs semantic search, it’s not always a keyword match but a contextual match.
Run an indexing workflow
The following workflow indexes the front page of Hacker News.
Let’s see how this workflow can be used with a console screencast.
The steps executed above are:
- Load hn.yml workflow
- Run the indexing workflow to load data
- Run a search and then re-run search with highlighting enabled
Note how in this example for the query recruitment
, hiring
is the main reason the matches were returned.
Search with SQL
Next we’ll run a similar workflow to the one above but define a translation function to select Spanish and French versions of the results.
This application is almost the same as above with one key difference. A translation pipeline is defined and that pipeline is defined as a SQL function. Let’s see the screencast below.
Note how a SQL statement is executed selecting the translations and filtering with a similarity query.
Article summarization
The next workflow summarizes the content of a URL.
Screencast of this workflow in action below.
The steps executed above are:
- Load article.yml workflow
- Run summary workflow for the txtai and paperai GitHub pages
Language Translation
Next up is a workflow that translate input text to French.
Let’s see the workflow in action.
The steps executed above are:
- Load translate.yml workflow
- Run translate workflow for snippets of text
Summarize and translate
Now let’s combine the last two workflows into a single summarize and translate workflow.
And the results are:
The steps executed above are:
- Load article-french.yml workflow
- Run summary workflow for URLs
Wrapping up
This article covered the txtai console through a series of examples. Everything seen here can be done programmatically. But the txtai console is an easy way to quickly run a workflow or embeddings searches.