Skip to content

Commit

Permalink
break out long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuan325 committed Jan 8, 2024
1 parent 58e5f2c commit c578717
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 17 deletions.
35 changes: 29 additions & 6 deletions retrieval_service/datastore/providers/cloudsql_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@ async def initialize_data(
# Insert all the data
await conn.execute(
text(
"""INSERT INTO amenities VALUES (:id, :name, :description, :location, :terminal, :category, :hour, :sunday_start_hour, :sunday_end_hour, :monday_start_hour, :monday_end_hour, :tuesday_start_hour, :tuesday_end_hour, :wednesday_start_hour, :wednesday_end_hour, :thursday_start_hour, :thursday_end_hour, :friday_start_hour, :friday_end_hour, :saturday_start_hour, :saturday_end_hour, :content, :embedding)"""
"""
INSERT INTO amenities VALUES (:id, :name, :description, :location,
:terminal, :category, :hour, :sunday_start_hour, :sunday_end_hour,
:monday_start_hour, :monday_end_hour, :tuesday_start_hour,
:tuesday_end_hour, :wednesday_start_hour, :wednesday_end_hour,
:thursday_start_hour, :thursday_end_hour, :friday_start_hour,
:friday_end_hour, :saturday_start_hour, :saturday_end_hour, :content, :embedding)
"""
),
[
{
Expand Down Expand Up @@ -209,7 +216,11 @@ async def initialize_data(
# Insert all the data
await conn.execute(
text(
"""INSERT INTO flights VALUES (:id, :airline, :flight_number, :departure_airport, :arrival_airport, :departure_time, :arrival_time, :departure_gate, :arrival_gate)"""
"""
INSERT INTO flights VALUES (:id, :airline, :flight_number,
:departure_airport, :arrival_airport, :departure_time,
:arrival_time, :departure_gate, :arrival_gate)
"""
),
[
{
Expand Down Expand Up @@ -305,8 +316,12 @@ async def get_amenity(self, id: int) -> Optional[models.Amenity]:
async with self.__pool.connect() as conn:
s = text(
"""
SELECT id, name, description, location, terminal, category, hour, sunday_start_hour, sunday_end_hour, monday_start_hour, monday_end_hour, tuesday_start_hour, tuesday_end_hour, wednesday_start_hour, wednesday_end_hour, thursday_start_hour, thursday_end_hour, friday_start_hour, friday_end_hour, saturday_start_hour, saturday_end_hour
FROM amenities WHERE id=:id
SELECT id, name, description, location, terminal, category, hour,
sunday_start_hour, sunday_end_hour, monday_start_hour, monday_end_hour,
tuesday_start_hour, tuesday_end_hour, wednesday_start_hour, wednesday_end_hour,
thursday_start_hour, thursday_end_hour, friday_start_hour, friday_end_hour,
saturday_start_hour, saturday_end_hour
FROM amenities WHERE id=:id
"""
)
params = {"id": id}
Expand All @@ -324,9 +339,17 @@ async def amenities_search(
async with self.__pool.connect() as conn:
s = text(
"""
SELECT id, name, description, location, terminal, category, hour, sunday_start_hour, sunday_end_hour, monday_start_hour, monday_end_hour, tuesday_start_hour, tuesday_end_hour, wednesday_start_hour, wednesday_end_hour, thursday_start_hour, thursday_end_hour, friday_start_hour, friday_end_hour, saturday_start_hour, saturday_end_hour
SELECT id, name, description, location, terminal, category, hour,
sunday_start_hour, sunday_end_hour, monday_start_hour, monday_end_hour,
tuesday_start_hour, tuesday_end_hour, wednesday_start_hour, wednesday_end_hour,
thursday_start_hour, thursday_end_hour, friday_start_hour, friday_end_hour,
saturday_start_hour, saturday_end_hour
FROM (
SELECT id, name, description, location, terminal, category, hour, sunday_start_hour, sunday_end_hour, monday_start_hour, monday_end_hour, tuesday_start_hour, tuesday_end_hour, wednesday_start_hour, wednesday_end_hour, thursday_start_hour, thursday_end_hour, friday_start_hour, friday_end_hour, saturday_start_hour, saturday_end_hour, 1 - (embedding <=> :query_embedding) AS similarity
SELECT id, name, description, location, terminal, category, hour,
sunday_start_hour, sunday_end_hour, monday_start_hour, monday_end_hour,
tuesday_start_hour, tuesday_end_hour, wednesday_start_hour, wednesday_end_hour,
thursday_start_hour, thursday_end_hour, friday_start_hour, friday_end_hour,
saturday_start_hour, saturday_end_hour, 1 - (embedding <=> :query_embedding) AS similarity
FROM amenities
WHERE 1 - (embedding <=> :query_embedding) > :similarity_threshold
ORDER BY similarity DESC
Expand Down
45 changes: 34 additions & 11 deletions retrieval_service/datastore/providers/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ async def initialize_data(
)
# Insert all the data
await conn.executemany(
"""INSERT INTO amenities VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)""",
"""
INSERT INTO amenities VALUES (
$1, $2, $3, $4, $5,
$6, $7, $8, $9, $10,
$11, $12, $13, $14, $15,
$16, $17, $18, $19, $20,
$21, $22, $23)
""",
[
(
a.id,
Expand Down Expand Up @@ -265,8 +272,13 @@ async def search_airports(
async def get_amenity(self, id: int) -> Optional[models.Amenity]:
result = await self.__pool.fetchrow(
"""
SELECT id, name, description, location, terminal, category, hour, sunday_start_hour, sunday_end_hour, monday_start_hour, monday_end_hour, tuesday_start_hour, tuesday_end_hour, wednesday_start_hour, wednesday_end_hour, thursday_start_hour, thursday_end_hour, friday_start_hour, friday_end_hour, saturday_start_hour, saturday_end_hour
FROM amenities WHERE id=$1
SELECT id, name, description, location, terminal,
category, hour, sunday_start_hour, sunday_end_hour,
monday_start_hour, monday_end_hour, tuesday_start_hour,
tuesday_end_hour, wednesday_start_hour, wednesday_end_hour,
thursday_start_hour, thursday_end_hour, friday_start_hour,
friday_end_hour, saturday_start_hour, saturday_end_hour
FROM amenities WHERE id=$1
""",
id,
)
Expand All @@ -282,14 +294,25 @@ async def amenities_search(
) -> list[models.Amenity]:
results = await self.__pool.fetch(
"""
SELECT id, name, description, location, terminal, category, hour, sunday_start_hour, sunday_end_hour, monday_start_hour, monday_end_hour, tuesday_start_hour, tuesday_end_hour, wednesday_start_hour, wednesday_end_hour, thursday_start_hour, thursday_end_hour, friday_start_hour, friday_end_hour, saturday_start_hour, saturday_end_hour
FROM (
SELECT id, name, description, location, terminal, category, hour, sunday_start_hour, sunday_end_hour, monday_start_hour, monday_end_hour, tuesday_start_hour, tuesday_end_hour, wednesday_start_hour, wednesday_end_hour, thursday_start_hour, thursday_end_hour, friday_start_hour, friday_end_hour, saturday_start_hour, saturday_end_hour, 1 - (embedding <=> $1) AS similarity
FROM amenities
WHERE 1 - (embedding <=> $1) > $2
ORDER BY similarity DESC
LIMIT $3
) AS sorted_amenities
SELECT id, name, description, location, terminal,
category, hour, sunday_start_hour, sunday_end_hour,
monday_start_hour, monday_end_hour, tuesday_start_hour,
tuesday_end_hour, wednesday_start_hour, wednesday_end_hour,
thursday_start_hour, thursday_end_hour, friday_start_hour,
friday_end_hour, saturday_start_hour, saturday_end_hour
FROM (
SELECT id, name, description, location, terminal, category,
hour, sunday_start_hour, sunday_end_hour, monday_start_hour,
monday_end_hour, tuesday_start_hour, tuesday_end_hour,
wednesday_start_hour, wednesday_end_hour, thursday_start_hour,
thursday_end_hour, friday_start_hour, friday_end_hour,
saturday_start_hour, saturday_end_hour,
1 - (embedding <=> $1) AS similarity
FROM amenities
WHERE 1 - (embedding <=> $1) > $2
ORDER BY similarity DESC
LIMIT $3
) AS sorted_amenities
""",
query_embedding,
similarity_threshold,
Expand Down

0 comments on commit c578717

Please sign in to comment.