Run your first vector search.

Start a local Skeg server, index three articles and retrieve the two closest matches.

Install Skeg ↗

Start Skeg locally

Use the installed skeg executable and Python 3. Start the server in one terminal and prepare the Python environment in another.

LOCAL SERVER
data_dir=$(mktemp -d)
skeg --data-dir "$data_dir" --addr 127.0.0.1:6379 --protocol resp3
PYTHON ENVIRONMENT
python3 -m venv .venv
. .venv/bin/activate
python -m pip install redis

Run the Python example

Copy or download the example and run python first_search.py in the Python environment above. It stores three vectors and prints the IDs, similarity scores and titles of the two closest matches.

The example supplies the vectors. To index your own text, use the same embedding model for documents and queries.

FIRST SEARCH GUIDE →
PYTHON · first_search.pyDownload
import os
import struct

import redis

port = int(os.environ.get("SKEG_LEARN_PORT", "6379"))
client = redis.Redis(
    host="127.0.0.1", port=port, protocol=3, decode_responses=False
)
index = "learn_search"


def vector(values):
    return struct.pack("<" + "f" * len(values), *values)


client.execute_command(
    "SKEG.VINDEX.CREATE", index, 4, "KIND", "tq2", "BACKEND", "disk",
    "PERSISTENCE", "durable", "IFNOTEXISTS",
)

articles = [
    (1, "Reset your password", [1.0, 0.0, 0.0, 0.0]),
    (2, "Download an invoice", [0.0, 1.0, 0.0, 0.0]),
    (3, "Recover account access", [0.8, 0.6, 0.0, 0.0]),
]
for row_id, title, coordinates in articles:
    client.set(f"article:{row_id}:title", title)
    client.execute_command("SKEG.VSET", index, row_id, vector(coordinates))

query = vector([1.0, 0.0, 0.0, 0.0])
hits = client.execute_command("SKEG.VSEARCH", index, 2, 100, query)

for offset in range(0, len(hits), 2):
    row_id, score = hits[offset:offset + 2]
    title = client.get(f"article:{int(row_id)}:title")
    print(f"{int(row_id)} {float(score):.3f} {title.decode('utf-8')}")

Embedding integrations

Follow each integration's setup guide for its embedding model, dimensions and supported server and client versions.

It runs on the machine you already have.

INSTALL IT →

One binary per platform, and it reads the processor it wakes up on. macOS on Apple silicon, Linux on arm64 or x86_64. The question is never whether the machine is big enough, only what you are willing to give it.

A LAPTOP

Beside the model, not instead of it.

The machine is already running something that wants the memory. skeg takes the disk, a bounded slice of RAM, and leaves the argument about the rest to somebody else.

A SMALL SERVER

The instance size follows the data.

Because the index is read from disk and only compact codes stay resident, adding vectors adds disk, not resident memory. You size the box for the corpus, not for the count.

A MACHINE WITH NO ROOM

Give it a ceiling and it obeys.

skeg reads the headroom the machine and its containers leave, and asks before it spends it. A write or a merge that would cross the line is refused with an error the client can see, instead of the process being killed mid-flight.

05 · GO DEEPER

Report a problem

Include your Skeg version, the steps to reproduce the issue and the result you expected.

Open an issue ↗