When you search internal documents or support histories, you miss results with keyword search when the words differ. You can miss a passage that answers the same question when the wording differs. You can recognize that two passages say the same thing in different words, but simple string matching has no way to recognize that difference. txtai is an embedding database that converts text into semantic vectors and searches them. I installed it and tested whether it could find a match when the query and result shared no words.
txtai is an all-in-one framework for building embedding-based search and LLM workflows. The project releases its source under the Apache 2.0 License (*1).
1. Install it
Fetch the embedding model (sentence-transformers/all-MiniLM-L6-v2) during the build with network access enabled.
FROM docker.io/library/python:3.12.13-slim
RUN pip install --no-cache-dir --quiet 'txtai==9.11.0'
COPY install_model.py /tmp/install_model.py
RUN python /tmp/install_model.py
WORKDIR /work
# install_model.py
import txtai
embeddings = txtai.Embeddings(path="sentence-transformers/all-MiniLM-L6-v2")
embeddings.index([(0, "warm up the model cache", None)])
print("warmup ok")
podman build -t txtai-sandbox .
2. Test a search with no shared words
I indexed five short sentences, then searched with a query that shared no words with any of them. I ran it with the network disconnected.
import txtai
embeddings = txtai.Embeddings(path="sentence-transformers/all-MiniLM-L6-v2")
documents = [
(0, "The cat sat quietly on the windowsill in the sun.", None),
(1, "Stock markets fell sharply after the interest rate announcement.", None),
(2, "A kitten curled up and slept on the warm windowsill.", None),
(3, "The central bank raised rates to fight inflation.", None),
(4, "She baked a loaf of sourdough bread this morning.", None),
]
embeddings.index(documents)
query = "a small cat napping by a window"
results = embeddings.search(query, 3)
for uid, score in results:
print(f"score={score:.3f} {documents[uid][1]}")
podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
-v "$(pwd)":/work -w /work txtai-sandbox \
python search_demo.py
The -v option makes the specified directory readable and writable from the container. Run this experiment in a dedicated empty directory, and do not place private keys or credentials there.
The command returned these results:
QUERY: a small cat napping by a window
score=0.638 A kitten curled up and slept on the warm windowsill.
score=0.612 The cat sat quietly on the windowsill in the sun.
score=0.243 She baked a loaf of sourdough bread this morning.
The query's napping does not appear in either sentence. The query's small does not match the word kitten either. The two cat sentences ranked first, while the unrelated bread sentence had a much lower score. The two finance sentences, about rate hikes and stock prices, did not make the top 3. txtai used semantic similarity alone, with zero string matches, to reorder the results.
Search without matching keyword phrasing
You do not need to use the same words as the indexed text. Embedding search lets you use your own wording. The system accounts for differences in expression and returns content with close meaning. You spend less time at the search box guessing which words return a match.
Sources
*1 txtai (GitHub), https://github.com/neuml/txtai, Apache 2.0 License