[STAGE2] pgvector infrastructure pilot
This commit is contained in:
1 parent
9340263940
commit
50c31091b2
2 files changed
+54
-1
No files matched your search
@@ -19,7 +19,7 @@ Gate G2: повтор события 100 раз = один эффект; пот
|
||||
| S2-03 | Inbox + effects idempotency | done |
|
||||
| S2-04 | NATS JetStream relay | done |
|
||||
| S2-05 | Adapters contract + ownership matrix | in_progress |
|
||||
| S2-06 | pgvector pilot | open |
|
||||
| S2-06 | pgvector pilot | done (synthetic infrastructure) |
|
||||
| S2-07 | Gate G2 proof | done |
|
||||
|
||||
## Проверка
|
||||
@@ -65,6 +65,14 @@ Consumer: `buryans-worker`
|
||||
}
|
||||
```
|
||||
|
||||
## pgvector pilot
|
||||
|
||||
```json
|
||||
{"extension":"vector","pilot":"synthetic-3d","nearest":"pilot-a","top2":["pilot-a","pilot-c"]}
|
||||
```
|
||||
|
||||
Важно: это инфраструктурный пилот, не production semantic search.
|
||||
|
||||
## Следующий инкремент
|
||||
|
||||
NATS JetStream:
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""pgvector pilot: extension, vector column, nearest-neighbor operator."""
|
||||
import json
|
||||
from event_store import connect
|
||||
|
||||
|
||||
def main():
|
||||
conn = connect()
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("create extension if not exists vector")
|
||||
cur.execute("""
|
||||
create table if not exists events.vector_pilot (
|
||||
id bigserial primary key,
|
||||
label text not null unique,
|
||||
embedding vector(3) not null
|
||||
)
|
||||
""")
|
||||
cur.execute("delete from events.vector_pilot where label like 'pilot-%'")
|
||||
cur.executemany(
|
||||
"insert into events.vector_pilot(label,embedding) values (%s,%s)",
|
||||
[("pilot-a", "[1,0,0]"), ("pilot-b", "[0,1,0]"), ("pilot-c", "[0.9,0.1,0]")],
|
||||
)
|
||||
cur.execute("""
|
||||
select label, embedding <-> '[1,0,0]'::vector as distance
|
||||
from events.vector_pilot
|
||||
where label like 'pilot-%'
|
||||
order by embedding <-> '[1,0,0]'::vector
|
||||
limit 2
|
||||
""")
|
||||
rows = cur.fetchall()
|
||||
cur.execute("delete from events.vector_pilot where label like 'pilot-%'")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print(json.dumps({
|
||||
"extension": "vector",
|
||||
"pilot": "synthetic-3d",
|
||||
"nearest": rows[0][0],
|
||||
"distance": float(rows[0][1]),
|
||||
"top2": [r[0] for r in rows],
|
||||
"note": "infrastructure pilot, not production semantic search",
|
||||
}, ensure_ascii=False))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user