Update and delete data
Replace an article vector, read it by ID and remove its related records.
Skeg 0.8 · Development documentation
An article can have a text key, a vector and a payload. In this exercise, you will update article 42, read back the stored text, vector and payload, then delete the article and check that both records are gone.
Start a local server
Install Skeg 0.8 and make sure port 6384 is free. Start a loopback server with a fresh data directory:
data_dir=$(mktemp -d) &&
skeg --protocol resp3 --data-dir "$data_dir" --addr 127.0.0.1:6384
In another terminal, activate a Python virtual environment and install the client:
python -m pip install 'redis>=5'
Download update_article.py and run
python update_article.py. The script creates a durable index named
article_updates. It reports two checks:
Article 42: updated text, vector and payload verified
Article 42: deleted text and vector verified absent
The next sections show the key calls from the script.
Replace the article
Give the article a stable ID. The script uses 42 both in the text key
article:42:text and as the row ID in the vector index. To update the article,
write the new text and replace the vector under the same ID:
new_text = b"Use the reset link, or follow the account recovery steps."
new_vector = struct.pack("<4f", 0.8, 0.6, 0.0, 0.0)
new_payload = b"topic=account revision=2"
client.set(text_key, new_text)
client.execute_command(
"SKEG.VSET", index, row_id, new_vector, "PAYLOAD", new_payload,
)
PAYLOAD replaces the entire payload. Include every field you want to keep
when supplying a replacement. Omit PAYLOAD to keep the existing payload.
Pass an empty byte string with PAYLOAD to clear its contents.
Use the index’s embedding model to generate the replacement vector from the revised text. The exercise uses fixed coordinates. If you change embedding models, build a separate index even if the dimensions match.
The text key and the vector row are separate records. SET and SKEG.VSET
can succeed independently. Keep the source text and intended revision so
you can reconcile an incomplete update. See
write outcomes.
Read the vector and payload by ID
Use SKEG.VGET ... WITHPAYLOAD when the server advertises the
vget.withpayload capability. It returns the vector,
payload, row version and index incarnation from the same read.
vector, payload, _version, _incarnation = client.execute_command(
"SKEG.VGET", index, row_id, "WITHPAYLOAD",
)
Compare the returned bytes with the vector and payload you wrote. Read the
article text separately with GET. Use plain SKEG.VGET when you only
need the vector. See the
vector API for
response types.
Delete the article
Delete the vector row and its payload with SKEG.VDEL, then delete the
separately stored text with DEL:
removed_vector = client.execute_command("SKEG.VDEL", index, row_id)
removed_text = client.delete(text_key)
Each command returns 1 if it removed its record and 0 if that record was
already absent. Check absence with plain SKEG.VGET for the vector and
GET for the text. Both should return null, represented by None in
Python. Space used by obsolete records can be reclaimed later by maintenance.
If the connection drops before you know both outcomes, check each record before resending a delete. Coordinate with any writers that could have recreated the article.
Finish the exercise
The script drops the example index after checking the deletes. If the script stops early, it may leave the index or text key in the exercise store. Stop Skeg with Ctrl+C and discard the temporary data directory if you no longer need it. Use a fresh directory to run the exercise again.
For metadata selection, continue with payloads and filters. For restart and backup procedures, see backup and restore.