Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CShorten committed Jan 14, 2025
1 parent 495c99c commit c4dbc53
Show file tree
Hide file tree
Showing 122 changed files with 7,413 additions and 71 deletions.
11 changes: 7 additions & 4 deletions app/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import json
import os

QUERIES_FILE = "synthetic-weaviate-queries-with-schemas.json"
QUERIES_FILE = "synthetic-weaviate-queries-with-results.json"

with open(QUERIES_FILE, 'r') as f:
synthetic_query_data = json.load(f)
Expand All @@ -29,7 +29,7 @@
# Example of the first row:
'''
{
"database_schema": "{\"weaviate_collections\":[{\"name\":\"Restaurants\",\"properties\":[{\"name\":\"name\",\"data_type\":[\"string\"],\"description\":\"The name of the restaurant.\"},{\"name\":\"description\",\"data_type\":[\"string\"],\"description\":\"A detailed description and summary of the restaurant, including cuisine type and ambiance.\"},{\"name\":\"averageRating\",\"data_type\":[\"number\"],\"description\":\"The average rating score out of 5 for the restaurant.\"},{\"name\":\"openNow\",\"data_type\":[\"boolean\"],\"description\":\"A flag indicating whether the restaurant is currently open.\"}],\"envisioned_use_case_overview\":\"This schema focuses on enabling users to discover restaurants based on a comprehensive profile. With semantic search, users can find restaurants by cuisine, ambiance, or special features.\"},{\"name\":\"Menus\",\"properties\":[{\"name\":\"menuItem\",\"data_type\":[\"string\"],\"description\":\"The name of the menu item.\"},{\"name\":\"itemDescription\",\"data_type\":[\"string\"],\"description\":\"A detailed description of the menu item, including ingredients and preparation style.\"},{\"name\":\"price\",\"data_type\":[\"number\"],\"description\":\"The price of the menu item.\"},{\"name\":\"isVegetarian\",\"data_type\":[\"boolean\"],\"description\":\"A flag to indicate if the menu item is vegetarian.\"}],\"envisioned_use_case_overview\":\"This schema assists in linking dining experiences with specific restaurants through their menus. Rich search features allow customers to find dishes tailored to dietary needs and price points.\"},{\"name\":\"Reservations\",\"properties\":[{\"name\":\"reservationName\",\"data_type\":[\"string\"],\"description\":\"The name under which the reservation is made.\"},{\"name\":\"notes\",\"data_type\":[\"string\"],\"description\":\"Detailed notes about the reservation, such as special requests or celebrations.\"},{\"name\":\"partySize\",\"data_type\":[\"number\"],\"description\":\"The number of persons in the reservation.\"},{\"name\":\"confirmed\",\"data_type\":[\"boolean\"],\"description\":\"A flag indicating whether the reservation is confirmed.\"}],\"envisioned_use_case_overview\":\"This schema integrates with the restaurants by managing booking experiences. Semantic search of reservations can uncover trends in dining preferences and commonly requested meal attributes.\"}]}",
"database_schema": "{\"weaviate_collections\":[{\"name\":\"Restaurants\",...}]}",
"query": {
"corresponding_natural_language_query": "What is the average price of seasonal specialty menu items under $20, grouped by whether they are vegetarian or not?",
"target_collection": "Menus",
Expand All @@ -48,7 +48,8 @@
"text_property_aggregation": null,
"boolean_property_aggregation": null,
"groupby_property": "isVegetarian"
}
},
"ground_truth_query_result": "Grouped aggregation results:\n----------------------------------------\nGroup: isVegetarian = true\nProperty: price\n mean: 15.5\nGroup count: 2\n----------------------------------------\nGroup: isVegetarian = false\nProperty: price\n mean: 17.0\nGroup count: 1\n"
}
'''

Expand All @@ -59,17 +60,19 @@ async def get_data():
class QueryUpdate(BaseModel):
index: int
updated_query: Dict[Any, Any]
updated_result: str

@app.put("/update-query")
async def update_query(query_update: QueryUpdate):
try:
if 0 <= query_update.index < len(synthetic_query_data):
synthetic_query_data[query_update.index]["query"] = query_update.updated_query
synthetic_query_data[query_update.index]["ground_truth_query_result"] = query_update.updated_result

with open(QUERIES_FILE, 'w') as f:
json.dump(synthetic_query_data, f, indent=2)

return {"message": "Query updated successfully"}
return {"message": "Query and result updated successfully"}
else:
raise HTTPException(status_code=404, detail="Query index not found")
except Exception as e:
Expand Down
6,802 changes: 6,802 additions & 0 deletions app/backend/synthetic-weaviate-queries-with-results.json

Large diffs are not rendered by default.

225 changes: 158 additions & 67 deletions app/frontend/src/components/QueryVisualizer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { ChevronLeft, ChevronRight, Database, Search, Check, X, Edit2, Save, ChevronDown, ChevronUp, Plus, Trash2 } from 'lucide-react';
import { ChevronLeft, ChevronRight, Database, Search, Check, X, Edit2, Save, ChevronDown, ChevronUp, Plus, Trash2, Home } from 'lucide-react';

const QueryEditor = ({ query, onSave, onCancel }) => {
const [editedQuery, setEditedQuery] = useState(query);
Expand Down Expand Up @@ -518,15 +518,103 @@ const QueryVisualizer = () => {
}));
};

const renderQueryResult = (result) => {
if (!result) return null;

// Attempt to parse JSON; if it fails, just show the string output
if (typeof result === 'string') {
try {
const parsedResult = JSON.parse(result);
// If parsing succeeded, we can optionally handle old logic here:
return (
<div className="mt-6 p-4 bg-gray-50 rounded-lg border border-gray-200">
<h3 className="text-lg font-semibold mb-4">Query Result</h3>

{/* If your backend still sometimes returns a structured JSON result: */}
{parsedResult.integer_aggregation_result !== undefined && (
<div className="mb-4">
<h4 className="font-medium text-sm text-gray-700">Integer Aggregation</h4>
<p className="text-lg">{parsedResult.integer_aggregation_result}</p>
</div>
)}

{parsedResult.text_aggregation_result && (
<div className="mb-4">
<h4 className="font-medium text-sm text-gray-700">Text Aggregation</h4>
{Array.isArray(parsedResult.text_aggregation_result) ? (
<ul className="list-disc pl-5">
{parsedResult.text_aggregation_result.map((item, idx) => (
<li key={idx}>{item}</li>
))}
</ul>
) : (
<p className="text-lg">{parsedResult.text_aggregation_result}</p>
)}
</div>
)}

{parsedResult.boolean_aggregation_result !== undefined && (
<div className="mb-4">
<h4 className="font-medium text-sm text-gray-700">Boolean Aggregation</h4>
<p className="text-lg">
{typeof parsedResult.boolean_aggregation_result === 'boolean'
? parsedResult.boolean_aggregation_result.toString()
: parsedResult.boolean_aggregation_result}
</p>
</div>
)}

{parsedResult.filtered_objects && parsedResult.filtered_objects.length > 0 && (
<div>
<h4 className="font-medium text-sm text-gray-700 mb-2">Filtered Objects</h4>
<div className="max-h-60 overflow-y-auto">
<pre className="bg-gray-100 p-3 rounded text-sm whitespace-pre-wrap">
{JSON.stringify(parsedResult.filtered_objects, null, 2)}
</pre>
</div>
</div>
)}
</div>
);
} catch (error) {
return (
<div className="mt-6 p-4 bg-gray-50 rounded-lg border border-gray-200">
<h3 className="text-lg font-semibold mb-4">Query Result</h3>
<pre className="whitespace-pre-wrap">{result}</pre>
</div>
);
}
}

// If it's not a string (e.g., already an object), fall back to your old rendering logic
const parsedResult = result;
return (
<div className="mt-6 p-4 bg-gray-50 rounded-lg border border-gray-200">
<h3 className="text-lg font-semibold mb-4">Query Result</h3>
{/* ...same logic as above for parsed objects... */}
</div>
);
};


return (
<div className="w-full p-6 min-h-screen bg-cover bg-center" style={{ backgroundImage: 'url("/background.png")' }}>
<div className="flex items-center mb-12 relative mt-8">
<button
onClick={() => navigate('/demo')}
className="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 flex items-center gap-2"
>
DBGorilla homepage
</button>
<div className="flex items-center gap-2">
<button
onClick={() => navigate('/')}
className="px-4 py-2 bg-[#1c1468] text-white rounded-lg hover:bg-[#130e4a] flex items-center gap-2"
>
<Home size={16} />
Home
</button>
<button
onClick={() => navigate('/demo')}
className="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 flex items-center gap-2"
>
Try it with Weaviate Agents
</button>
</div>
<h1 className="text-4xl font-bold text-[#1c1468] absolute left-1/2 -translate-x-1/2">Dataset Visualizer</h1>
<button
onClick={() => navigate('/search')}
Expand Down Expand Up @@ -617,66 +705,69 @@ const QueryVisualizer = () => {
onCancel={() => setIsEditing(false)}
/>
) : (
<div className="space-y-2">
{currentItem.query.corresponding_natural_language_query && (
<p><span className="font-semibold">Natural Language Query:</span> {currentItem.query.corresponding_natural_language_query}</p>
)}
{currentItem.query.target_collection && (
<p><span className="font-semibold">Collection:</span> {currentItem.query.target_collection}</p>
)}
{currentItem.query.search_query && (
<p><span className="font-semibold">Search Query:</span> {currentItem.query.search_query}</p>
)}
{currentItem.query.integer_property_filter && (
<p>
<span className="font-semibold">Integer Filter:</span>{' '}
{currentItem.query.integer_property_filter.property_name}{' '}
{currentItem.query.integer_property_filter.operator}{' '}
{currentItem.query.integer_property_filter.value}
</p>
)}
{currentItem.query.text_property_filter && (
<p>
<span className="font-semibold">Text Filter:</span>{' '}
{currentItem.query.text_property_filter.property_name}{' '}
{currentItem.query.text_property_filter.operator}{' '}
{currentItem.query.text_property_filter.value}
</p>
)}
{currentItem.query.boolean_property_filter && (
<p>
<span className="font-semibold">Boolean Filter:</span>{' '}
{currentItem.query.boolean_property_filter.property_name} = {' '}
{currentItem.query.boolean_property_filter.value}
</p>
)}
{currentItem.query.integer_property_aggregation && (
<p>
<span className="font-semibold">Integer Aggregation:</span>{' '}
{currentItem.query.integer_property_aggregation.metrics} of{' '}
{currentItem.query.integer_property_aggregation.property_name}
</p>
)}
{currentItem.query.text_property_aggregation && (
<p>
<span className="font-semibold">Text Aggregation:</span>{' '}
{currentItem.query.text_property_aggregation.metrics} of{' '}
{currentItem.query.text_property_aggregation.property_name}
{currentItem.query.text_property_aggregation.top_occurrences_limit &&
` (Top ${currentItem.query.text_property_aggregation.top_occurrences_limit})`}
</p>
)}
{currentItem.query.boolean_property_aggregation && (
<p>
<span className="font-semibold">Boolean Aggregation:</span>{' '}
{currentItem.query.boolean_property_aggregation.metrics} of{' '}
{currentItem.query.boolean_property_aggregation.property_name}
</p>
)}
{currentItem.query.groupby_property && (
<p><span className="font-semibold">Group By:</span> {currentItem.query.groupby_property}</p>
)}
</div>
<>
<div className="space-y-2">
{currentItem.query.corresponding_natural_language_query && (
<p><span className="font-semibold">Natural Language Query:</span> {currentItem.query.corresponding_natural_language_query}</p>
)}
{currentItem.query.target_collection && (
<p><span className="font-semibold">Collection:</span> {currentItem.query.target_collection}</p>
)}
{currentItem.query.search_query && (
<p><span className="font-semibold">Search Query:</span> {currentItem.query.search_query}</p>
)}
{currentItem.query.integer_property_filter && (
<p>
<span className="font-semibold">Integer Filter:</span>{' '}
{currentItem.query.integer_property_filter.property_name}{' '}
{currentItem.query.integer_property_filter.operator}{' '}
{currentItem.query.integer_property_filter.value}
</p>
)}
{currentItem.query.text_property_filter && (
<p>
<span className="font-semibold">Text Filter:</span>{' '}
{currentItem.query.text_property_filter.property_name}{' '}
{currentItem.query.text_property_filter.operator}{' '}
{currentItem.query.text_property_filter.value}
</p>
)}
{currentItem.query.boolean_property_filter && (
<p>
<span className="font-semibold">Boolean Filter:</span>{' '}
{currentItem.query.boolean_property_filter.property_name} = {' '}
{currentItem.query.boolean_property_filter.value}
</p>
)}
{currentItem.query.integer_property_aggregation && (
<p>
<span className="font-semibold">Integer Aggregation:</span>{' '}
{currentItem.query.integer_property_aggregation.metrics} of{' '}
{currentItem.query.integer_property_aggregation.property_name}
</p>
)}
{currentItem.query.text_property_aggregation && (
<p>
<span className="font-semibold">Text Aggregation:</span>{' '}
{currentItem.query.text_property_aggregation.metrics} of{' '}
{currentItem.query.text_property_aggregation.property_name}
{currentItem.query.text_property_aggregation.top_occurrences_limit &&
` (Top ${currentItem.query.text_property_aggregation.top_occurrences_limit})`}
</p>
)}
{currentItem.query.boolean_property_aggregation && (
<p>
<span className="font-semibold">Boolean Aggregation:</span>{' '}
{currentItem.query.boolean_property_aggregation.metrics} of{' '}
{currentItem.query.boolean_property_aggregation.property_name}
</p>
)}
{currentItem.query.groupby_property && (
<p><span className="font-semibold">Group By:</span> {currentItem.query.groupby_property}</p>
)}
</div>
{renderQueryResult(currentItem.ground_truth_query_result)}
</>
)}
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions data/Appointments.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
patientName,appointmentNotes,appointmentDuration,appointmentConfirmed
"Alice Johnson","Annual physical examination with focus on managing hypertension. Patient requesting blood work and medication review.",30,true
"Robert Martinez","Follow-up cardiac consultation post-stress test. Discussion of preventive measures and lifestyle modifications needed.",45,true
"Maria Williams","First trimester pregnancy check-up. Ultrasound scheduled. Patient has questions about genetic screening options.",60,false
4 changes: 4 additions & 0 deletions data/ArtPieces.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
artPieceName,artPieceHistory,currentValuation,onDisplay
"Starry Night","Created by Vincent van Gogh in June 1889, during his stay at the Saint-Paul-de-Mausole asylum. The legendary night sky was inspired by the view from his asylum room window, stylized through memory and emotion. The swirling patterns reflect both astronomical phenomena and the artist's internal turmoil.",100000000,true
"Water Lilies (Nymphéas)","Part of Claude Monet's famous Water Lilies series, painted between 1920-1926. Created in his garden at Giverny, these large-scale works represent the culmination of his artistic vision. The series captures changing light effects on his water garden throughout different times of day.",84000000,true
"Rosetta Stone","Ancient Egyptian granodiorite stele inscribed with three versions of a decree issued in Memphis in 196 BC. Discovery in 1799 led to the breakthrough in understanding hieroglyphic writing. The text appears in hieroglyphic, Demotic script, and ancient Greek.",150000000,false
4 changes: 4 additions & 0 deletions data/Clinics.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
clinicName,description,averagePatientSatisfaction,acceptingNewPatients
"Evergreen Family Practice","A comprehensive family medicine clinic offering preventive care, chronic disease management, and pediatric services. Features modern facilities with an emphasis on holistic health approaches and patient education.",4.8,true
"Metropolitan Cardiology Center","Specialized cardiac care facility equipped with state-of-the-art diagnostic equipment. Offers comprehensive cardiovascular services including preventive cardiology, interventional procedures, and rehabilitation programs.",4.6,false
"Wellness Women's Health","Dedicated women's health clinic providing gynecological care, obstetrics, and preventive health services. Offers a supportive environment with focus on personalized care and patient comfort.",4.9,true
4 changes: 4 additions & 0 deletions data/Courses.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
courseTitle,courseDescription,courseDuration,currentlyEnrolling
"Advanced Machine Learning","Deep dive into neural networks, reinforcement learning, and deep learning architectures. Includes hands-on projects with real-world datasets and implementation of state-of-the-art algorithms. Focus on both theoretical foundations and practical applications.",48,true
"Environmental Biology","Comprehensive study of ecosystems, biodiversity, and human impact on the environment. Features field work, laboratory experiments, and research projects on local ecology. Emphasizes sustainable practices and conservation biology.",36,true
"Modern World History","Analysis of global historical events from 1750 to present, examining social movements, technological revolutions, and geopolitical changes. Incorporates primary source analysis and comparative historical methods.",42,false
Loading

0 comments on commit c4dbc53

Please sign in to comment.