Skip to content

Commit f9863c3

Browse files
committed
Improved example [skip ci]
1 parent de5ae8e commit f9863c3

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

examples/openai/example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import numpy as np
21
from openai import OpenAI
2+
from pgvector import Vector
33
from pgvector.psycopg import register_vector
44
import psycopg
55

@@ -25,10 +25,10 @@ def embed(input):
2525
]
2626
embeddings = embed(input)
2727
for content, embedding in zip(input, embeddings):
28-
conn.execute('INSERT INTO documents (content, embedding) VALUES (%s, %s)', (content, np.array(embedding)))
28+
conn.execute('INSERT INTO documents (content, embedding) VALUES (%s, %s)', (content, Vector(embedding)))
2929

3030
query = 'forest'
3131
query_embedding = embed([query])[0]
32-
result = conn.execute('SELECT content FROM documents ORDER BY embedding <=> %s LIMIT 5', (np.array(query_embedding),)).fetchall()
32+
result = conn.execute('SELECT content FROM documents ORDER BY embedding <=> %s LIMIT 5', (Vector(query_embedding),)).fetchall()
3333
for row in result:
3434
print(row[0])

0 commit comments

Comments
 (0)