8 November 2026 · Practical AI builds
How do I add a search box that understands meaning to my own documents?
By the end of this you will have a small search box that finds passages in your own documents by what they mean, not just by the exact words you type. Search for "customer wants money back" and it will find the note that says "refund request". It suits anyone with a pile of notes, policies or help pages who is tired of keyword search missing things.
I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.
What you need
- Your documents as plain text. Word files and PDFs can be exported to text first.
- A computer or small server with Python 3 installed. A laptop is fine for a few thousand documents.
- A free, open-source embedding model. The
sentence-transformerslibrary and its smallall-MiniLM-L6-v2model run on an ordinary processor with no graphics card. - Basic comfort with copying commands into a terminal. You do not need to be a developer.
- Optional: a hosted embedding service from one of the big AI providers instead of a local model. These charge per use, so check the current pricing before you rely on one.
Step by step
- Put all the documents you want to search into one folder as
.txtor.mdfiles, so there is one place to read from. - Split each document into chunks of a paragraph or two. Models like this only read a limited amount of text at once and quietly ignore the rest, and short chunks also give more precise results.
- Keep the file name (and a heading if you have one) with every chunk, so a result can tell you where it came from.
- Create a Python virtual environment and install the library with
pip install sentence-transformers. The model downloads itself the first time you use it. - Turn every chunk into an embedding. An embedding is a list of numbers that describes what the text is about, so texts with similar meaning end up with similar numbers.
- Save those embeddings to disk along with the chunks. You only need to do this once per document, not every time someone searches.
- When someone searches, turn their words into an embedding in the same way and compare it with the saved ones. Show the five closest chunks, with their file names and a similarity score.
- Once it works in the terminal, put a simple web form in front of it with a small framework such as Flask, and keep it private if the documents are.
- Re-run the embedding step whenever documents are added or changed. A nightly scheduled job does this without you having to remember.
Here is the core of it in a few lines, to show how little is involved:
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer("all-MiniLM-L6-v2")
chunks = ["Refund requests must be made within 30 days.",
"Our van parks behind the hall on Saturdays.",
"Invoices are sent by email at the end of each month."]
chunk_vecs = model.encode(chunks, convert_to_tensor=True)
query_vec = model.encode("customer wants money back", convert_to_tensor=True)
for hit in util.semantic_search(query_vec, chunk_vecs, top_k=2)[0]:
print(round(hit["score"], 2), chunks[hit["corpus_id"]])For a real folder you would read the chunks from your files and save chunk_vecs to disk, but the idea stays the same. Once you have this, it is a short step to a chatbot that answers from the same passages, which is covered in how to build a chatbot that answers from your own files. If the search page sits on a server, putting a simple password in front of a private web tool keeps it to the people it is meant for.
What good looks like
Test it with questions worded differently from your documents. If you search "staff holiday rules" and the top result is the paragraph headed "annual leave policy", it is working. Results should come back in well under a second for a few thousand chunks, and the scores for good matches should be clearly higher than for unrelated ones. Keep a short list of test searches with the answers you expect, and run them again after any change.
Watch out for
- Exact codes and names. Meaning-based search can be poor at part numbers, invoice references and unusual surnames, because those carry little meaning. Many people run an ordinary keyword search alongside it and show both sets of results.
- Privacy and accuracy. A local model keeps your documents on your own machine. A hosted service sends the text to someone else, so check its terms before you send anything personal or confidential. The search can also surface an old or wrong passage with confidence, so treat results as pointers and check the source document for anything that matters.
Questions people ask
Do I need a special vector database?
Not for a small collection. A few thousand chunks fit comfortably in a single file in memory, and a dedicated vector database only starts to pay off when you have far more text or many users.
Does it work in languages other than English?
The small model used here is trained mainly on English. There are multilingual embedding models that work the same way, so choose one of those if your documents are in several languages.
In short, you turn your documents and each search into embeddings, compare them, and show the closest passages with their sources. It takes a free model, a few lines of Python and a regular refresh to find notes by what they are about.
Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.