You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/sqlalchemy_items.py
+23-8Lines changed: 23 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -39,23 +39,30 @@ class Item(Base):
39
39
40
40
engine=create_engine(DATABASE_URI, echo=False)
41
41
42
-
# Create tables in database
42
+
# Create pgvector extension
43
+
withengine.begin() asconn:
44
+
conn.execute(text("CREATE EXTENSION IF NOT EXISTS vector"))
45
+
46
+
# Drop all tables defined in this model from the database, if they already exist
43
47
Base.metadata.drop_all(engine)
48
+
# Create all tables defined in this model in the database
44
49
Base.metadata.create_all(engine)
45
50
46
51
# Insert data and issue queries
47
52
withSession(engine) assession:
48
-
session.execute(text("CREATE EXTENSION IF NOT EXISTS vector"))
49
-
53
+
# Define HNSW index to support vector similarity search through the vector_l2_ops access method (Euclidean distance). The SQL operator for Euclidean distance is written as <->.
0 commit comments