Search text with local embeddings
Embed five articles and a question locally, search Skeg and retrieve the matching text.
Skeg 0.8 · Development documentation
Use a local model to turn five help-centre articles and a question into vectors. Search those vectors with Skeg, then read the original article text by row ID. Ollama generates the embeddings. Skeg stores the records and searches the vectors.
flowchart TD
accTitle: Search articles with local embeddings
accDescr: The application sends articles and a question to Ollama. It stores article vectors and text in Skeg, searches using the question vector and reads the matching text by ID.
A["Articles and a question"] --> B["Ollama creates embeddings"]
B --> C["Store article text and vectors"]
C --> D["Search using the question vector"]
D --> E["Read article text by ID"]
Prepare the model and client
Install Skeg 0.8 and have Python 3.10 or later with virtual environment support. Run Ollama locally on port 11434. Check the model’s requirements and allow space for the download. See the EmbeddingGemma model page.
From a new working directory, download the model and prepare the Python environment:
ollama pull embeddinggemma &&
python3 -m venv .venv &&
. .venv/bin/activate &&
python -m pip install 'redis>=5'
The download requires network access. During the exercise the script sends article text and questions to the local Ollama endpoint.
Start Skeg
Use a fresh local data directory and an available port 6388. Start Skeg in a separate terminal:
data_dir=$(mktemp -d) &&
skeg --protocol resp3 --data-dir "$data_dir" --addr 127.0.0.1:6388
The exercise uses loopback listeners. For a shared deployment, configure authentication and follow deployment.
Run the example
Save semantic_search.py in the Python working directory and run it from the activated environment:
python semantic_search.py
The script sends the articles and question to Ollama in one embedding
request. Article prompts include the title and text. The question uses the
model’s retrieval prefix. See the
EmbeddingGemma prompt instructions.
The request uses truncate: false so oversized input returns an error.
See the Ollama embedding endpoint.
After receiving the vectors, the script uses their dimension to create a temporary flat index that compares the five article vectors directly. It stores each article as a key-value record and writes one vector under the corresponding row ID. It then searches with the question vector and reads the articles for the returned IDs. The article keys are stored separately and can remain after an interrupted run.
Expect the model name, vector dimension and question, followed by each hit’s ID, score and article text. For the default question, look for the password reset and account recovery articles. Review the returned text against the question. Scores and order can vary with the model artifact and the search.
Try another question
python semantic_search.py --query 'Where can I get a receipt for my payment?'
Each run embeds the articles again, creates a fresh index and removes its own records on success. In an application, store the article vectors once and compute a new embedding for each question. Keep the model revision and preprocessing with the index. If you change models, re-embed the articles and load a separate index.
If a step fails
| Symptom | What to check |
|---|---|
| Ollama is unreachable or lacks the model | Check the loopback listener at port 11434 and complete the model download. |
| Embedding fails before the script prints an index name | Check the Ollama response and logs. This step runs before the script writes to Skeg. |
| Skeg is unreachable | Check the server terminal and port 6388. |
| Skeg refuses the connection | Check that you are using the local exercise server. For shared servers, use the configured login procedure. |
| A write fails or the connection drops after an index name is printed | Save that name and inspect the index and its KV keys. Follow write outcomes before resending writes. |
| The results seem unrelated | Check the model, question and article content. Follow search troubleshooting. |
Finish the exercise
A successful run drops its index and deletes its article keys. If a failed
run leaves data, use the printed index name in the following commands.
With redis-cli installed, replace semantic_demo_REPLACE in the first line:
demo_index=semantic_demo_REPLACE
redis-cli -3 -h 127.0.0.1 -p 6388 SKEG.VINDEX.DROP "$demo_index"
redis-cli -3 -h 127.0.0.1 -p 6388 DEL \
"$demo_index:article:1" "$demo_index:article:2" "$demo_index:article:3" \
"$demo_index:article:4" "$demo_index:article:5"
Check both replies. A missing index can return an error. DEL counts
only the keys it removed. Stop Skeg with Ctrl+C. If you no longer need
the exercise, remove its temporary data directory after shutdown.
For a larger import, see batch ingestion. To restrict eligible articles, see payloads and filters.