Skip to content

Commit 9dd4a3c

Browse files
committed
Making restaurant data changes
1 parent 541adda commit 9dd4a3c

File tree

7 files changed

+1133
-14
lines changed

7 files changed

+1133
-14
lines changed

convert_csv_json.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import ast
2+
import csv
3+
import json
4+
5+
# Read CSV file - Using the correct dialect to handle quotes properly
6+
with open("data.csv", encoding="utf-8") as csv_file:
7+
# Use the csv.reader with proper quoting parameters
8+
csv_reader = csv.reader(csv_file, quoting=csv.QUOTE_ALL, doublequote=True, escapechar="\\")
9+
header = next(csv_reader) # Get the header row
10+
data = list(csv_reader) # Get all data rows
11+
12+
# Convert to JSON format
13+
json_data = []
14+
for row in data:
15+
item = {}
16+
for i in range(len(header)):
17+
if i < len(row): # Ensure we don't go out of bounds
18+
value = row[i].strip()
19+
# Check if the value looks like a JSON array
20+
if value.startswith("[") and value.endswith("]"):
21+
try:
22+
# Parse the JSON-like string into a Python object
23+
value = json.loads(value.replace("'", '"'))
24+
except (ValueError, SyntaxError):
25+
try:
26+
# Try with ast as a fallback
27+
value = ast.literal_eval(value)
28+
except (ValueError, SyntaxError):
29+
# If parsing fails, keep it as a string
30+
pass
31+
# Convert boolean strings
32+
elif value.lower() == "true":
33+
value = True
34+
elif value.lower() == "false":
35+
value = False
36+
# Try to convert numbers
37+
elif value.isdigit():
38+
value = int(value)
39+
elif value.replace(".", "", 1).isdigit() and value.count(".") <= 1:
40+
value = float(value)
41+
42+
item[header[i]] = value
43+
# remove is_open column
44+
del item["is_open"]
45+
json_data.append(item)
46+
47+
# Write to JSON file
48+
with open("data.json", "w", encoding="utf-8") as f:
49+
json.dump(json_data, f, indent=4, ensure_ascii=False)
50+
51+
print(f"Successfully converted CSV data to JSON format with {len(json_data)} records")

data.csv

Lines changed: 51 additions & 0 deletions
Large diffs are not rendered by default.

data.json

Lines changed: 1002 additions & 0 deletions
Large diffs are not rendered by default.

evals/generate_ground_truth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from sqlalchemy import create_engine, select
1313
from sqlalchemy.orm import Session
1414

15-
from fastapi_app.postgres_models import Item
15+
from fastapi_app.postgres_models import Restaurant
1616

1717
logger = logging.getLogger("ragapp")
1818

src/backend/fastapi_app/api_models.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,21 @@ class RetrievalResponseDelta(BaseModel):
7171

7272
class ItemPublic(BaseModel):
7373
id: int
74-
type: str
75-
brand: str
7674
name: str
75+
location: str
76+
cuisine: str
77+
rating: int
78+
price_level: int
79+
review_count: int
80+
hours: int
81+
tags: str
7782
description: str
78-
price: float
83+
menu_summary: str
84+
top_reviews: str
85+
vibe: str
7986

8087

81-
class ItemWithDistance(ItemPublic):
88+
class ItemPublicWithDistance(RestaurantPublic):
8289
distance: float
8390

8491
def __init__(self, **data):

src/backend/fastapi_app/postgres_models.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ class Base(DeclarativeBase):
1313
class Item(Base):
1414
__tablename__ = "items"
1515
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
16-
type: Mapped[str] = mapped_column()
17-
brand: Mapped[str] = mapped_column()
1816
name: Mapped[str] = mapped_column()
17+
location: Mapped[str] = mapped_column()
18+
cuisine: Mapped[str] = mapped_column()
19+
rating: Mapped[int] = mapped_column()
20+
price_level: Mapped[int] = mapped_column()
21+
review_count: Mapped[int] = mapped_column()
22+
hours: Mapped[str] = mapped_column()
23+
tags: Mapped[str] = mapped_column() # JSON array
1924
description: Mapped[str] = mapped_column()
20-
price: Mapped[float] = mapped_column()
25+
menu_summary: Mapped[str] = mapped_column()
26+
top_reviews: Mapped[str] = mapped_column()
27+
vibe: Mapped[str] = mapped_column()
28+
2129
# Embeddings for different models:
2230
embedding_3l: Mapped[Vector] = mapped_column(Vector(1024), nullable=True) # text-embedding-3-large
2331
embedding_nomic: Mapped[Vector] = mapped_column(Vector(768), nullable=True) # nomic-embed-text
@@ -33,11 +41,10 @@ def to_dict(self, include_embedding: bool = False):
3341
return model_dict
3442

3543
def to_str_for_rag(self):
36-
return f"Name:{self.name} Description:{self.description} Price:{self.price} Brand:{self.brand} Type:{self.type}"
37-
44+
return f"Name:{self.name} Description:{self.description} Location:{self.location} Cuisine:{self.cuisine} Rating:{self.rating} Price Level:{self.price_level} Review Count:{self.review_count} Hours:{self.hours} Tags:{self.tags} Menu Summary:{self.menu_summary} Top Reviews:{self.top_reviews} Vibe:{self.vibe}"
45+
3846
def to_str_for_embedding(self):
39-
return f"Name: {self.name} Description: {self.description} Type: {self.type}"
40-
47+
return f"Name: {self.name} Description: {self.description} Cuisine: {self.cuisine} Tags: {self.tags} Menu Summary: {self.menu_summary} Top Reviews: {self.top_reviews} Vibe: {self.vibe}"
4148

4249
"""
4350
**Define HNSW index to support vector similarity search**

src/frontend/src/components/Answer/Answer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ export const Answer = ({
6868
return (
6969
<li key={rowId}>
7070
<h4>{citation.name}</h4>
71-
<p className={styles.referenceMetadata}>Brand: {citation.brand}</p>
72-
<p className={styles.referenceMetadata}>Price: {citation.price}</p>
71+
<p className={styles.referenceMetadata}>Location: {citation.location}</p>
72+
<p className={styles.referenceMetadata}>Price level: {citation.price_level}</p>
73+
<p className={styles.referenceMetadata}>Rating: {citation.rating}</p>
7374
<p>{citation.description}</p>
7475
</li>
7576
);

0 commit comments

Comments
 (0)