Skip to content

Commit 9762b5b

Browse files
committed
Black formatting
1 parent b36d043 commit 9762b5b

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

examples/sqlalchemy_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Item(Base):
2121
id: Mapped[int] = mapped_column(primary_key=True)
2222
embedding = mapped_column(Vector(3))
2323

24+
2425
# 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 <->.
2526
index = Index(
2627
"hnsw_index_for_euclidean_distance_similarity_search",
@@ -30,6 +31,7 @@ class Item(Base):
3031
postgresql_ops={"embedding": "vector_l2_ops"},
3132
)
3233

34+
3335
async def insert_objects(async_session: async_sessionmaker[AsyncSession]) -> None:
3436
async with async_session() as session:
3537
async with session.begin():

examples/sqlalchemy_items.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Item(Base):
1717
id: Mapped[int] = mapped_column(primary_key=True)
1818
embedding = mapped_column(Vector(3))
1919

20+
2021
# 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 <->.
2122
index = Index(
2223
"hnsw_index_for_euclidean_distance_similarity_search",

examples/sqlalchemy_movies.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Movie(Base):
2020
title: Mapped[str] = mapped_column()
2121
title_vector = mapped_column(Vector(1536)) # ada-002 is 1536-dimensional
2222

23+
2324
# Define HNSW index to support vector similarity search through the vector_cosine_ops access method (cosine distance). The SQL operator for cosine distance is written as <=>.
2425
index = Index(
2526
"hnsw_index_for_cosine_distance_similarity_search",
@@ -81,9 +82,8 @@ class Movie(Base):
8182

8283
# Find the 5 most similar movies to "Winnie the Pooh"
8384
most_similars = session.scalars(
84-
select(Movie).order_by(
85-
Movie.title_vector.cosine_distance(target_movie.title_vector)
86-
).limit(5))
85+
select(Movie).order_by(Movie.title_vector.cosine_distance(target_movie.title_vector)).limit(5)
86+
)
8787
print(f"Five most similar movies to '{target_movie.title}':")
8888
for movie in most_similars:
8989
print(f"\t{movie.title}")

0 commit comments

Comments
 (0)