docs(vector): add write-RPC migration instructions (existing_vector_hashes + upsert_vector_records)
The original doc only covered search_similar; the write functions also need solved_question in their kind whitelist for the memory table. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -97,5 +97,54 @@ quando assente.
|
||||
`tht memory search "<domanda>" --json` devono continuare a funzionare (il secondo
|
||||
ora senza righe solved nei top-k).
|
||||
|
||||
**Non toccare** `existing_vector_hashes` e `upsert_vector_records` (path di scrittura):
|
||||
già ricevono `kinds`/`kind` e non sono coinvolte.
|
||||
## Funzioni di scrittura: `existing_vector_hashes` e `upsert_vector_records`
|
||||
|
||||
Entrambe hanno una validazione interna che ammette solo i kind storici per ogni tabella.
|
||||
Per la tabella `memory`, il set ammesso va ampliato a `{"memory", "solved_question"}`.
|
||||
|
||||
**Come trovare la validazione.** Recupera la definizione di ciascuna funzione:
|
||||
```sql
|
||||
SELECT pg_get_functiondef(oid) FROM pg_proc WHERE proname = 'existing_vector_hashes';
|
||||
SELECT pg_get_functiondef(oid) FROM pg_proc WHERE proname = 'upsert_vector_records';
|
||||
```
|
||||
Cerca la riga che controlla i kind ammessi (es. `IF kind NOT IN ('memory') THEN RAISE`,
|
||||
oppure un array literal `ARRAY['memory']`, oppure una lookup su una tabella di
|
||||
configurazione). La modifica è semplicemente aggiungere `'solved_question'` alla lista
|
||||
ammessa per `memory`.
|
||||
|
||||
**Esempio di pattern tipico:**
|
||||
```sql
|
||||
-- PRIMA:
|
||||
IF NOT (kind = ANY(ARRAY['memory'])) THEN
|
||||
RAISE EXCEPTION 'Invalid kind for %', table_name;
|
||||
END IF;
|
||||
|
||||
-- DOPO:
|
||||
IF NOT (kind = ANY(ARRAY['memory', 'solved_question'])) THEN
|
||||
RAISE EXCEPTION 'Invalid kind for %', table_name;
|
||||
END IF;
|
||||
```
|
||||
|
||||
Applica la stessa tecnica DROP+CREATE in transazione già usata per `search_similar`
|
||||
(mai `CREATE OR REPLACE` con firma diversa). Ripristina i GRANT dopo il DROP.
|
||||
|
||||
**Test delle funzioni di scrittura** (con la API key writer):
|
||||
```bash
|
||||
# existing_vector_hashes — deve accettare kinds = ['solved_question']
|
||||
curl -s -X POST "<write_base_url>/rpc/existing_vector_hashes" -H "X-API-Key: $WRITE_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"table_name": "memory", "kinds": ["solved_question"]}'
|
||||
# atteso: 200 con array (vuoto o con hash)
|
||||
|
||||
# upsert_vector_records — deve accettare kind = 'solved_question'
|
||||
curl -s -X POST "<write_base_url>/rpc/upsert_vector_records" -H "X-API-Key: $WRITE_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"table_name": "memory", "rows": [{"record_key": "solved:__test__", "kind": "solved_question", "content_hash": "test", "metadata": {"id": "solved:__test__", "kind": "solved_question"}, "embedding": [0.0]}]}'
|
||||
# atteso: 200 (upsert riuscito); l'embedding dummy verrà sovrascritto dal test vero
|
||||
```
|
||||
|
||||
Dopo aver applicato le modifiche e verificato con curl, ritesta dal workstation:
|
||||
```bash
|
||||
tht memory solved-index -c workspaces/psd.yaml <session_id>
|
||||
tht memory solved-search -c workspaces/psd.yaml "domanda di test" --json
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user