-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Clean up sample app and finalize endpoints #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| from fastapi import FastAPI | ||||||
| from fastapi.middleware.cors import CORSMiddleware | ||||||
| from src.routers import movies | ||||||
| from src.utils.errorHandler import register_error_handlers | ||||||
| from src.utils.errorHandler import register_error_handlers, create_error_response | ||||||
| from src.database.mongo_client import db, get_collection | ||||||
| import traceback | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we're not using this import - maybe it's left over from a prior version of this file?
Suggested change
|
||||||
| import os | ||||||
|
|
@@ -34,7 +34,6 @@ async def ensure_search_index(): | |||||
| indexes = [idx async for idx in result] | ||||||
| index_names = [index["name"] for index in indexes] | ||||||
| if "movieSearchIndex" in index_names: | ||||||
| print("MongoDB Search index already exists.") | ||||||
| return | ||||||
|
|
||||||
| # Create a mapping if the movieSearchIndex does not exist | ||||||
|
|
@@ -58,9 +57,12 @@ async def ensure_search_index(): | |||||
| "definition": index_definition | ||||||
| }] | ||||||
| }) | ||||||
| print("MongoDB Search index created.") | ||||||
| except Exception as e: | ||||||
| print(f"Error creating the search index: {e}") | ||||||
| raise RuntimeError( | ||||||
| f"Failed to create search index 'movieSearchIndex': {str(e)}. " | ||||||
| f"Search functionality may not work properly. " | ||||||
| f"Please check your MongoDB Atlas configuration and ensure the cluster supports search indexes." | ||||||
| ) | ||||||
|
|
||||||
| @app.on_event("startup") | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the I don't know how big of a lift it is to switch to the lifespan event handler. If this isn't a quick fix, I'd say we should scope this for a fast follow given the release timeline. But ideally we would not release a brand new sample app that uses deprecated APIs.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i will look into this and try to implement it in my upcoming push! |
||||||
| async def vector_search_index(): | ||||||
|
|
@@ -69,7 +71,6 @@ async def vector_search_index(): | |||||
| This ensures the index is ready before any vector search requests are made. | ||||||
| """ | ||||||
| try: | ||||||
|
|
||||||
| embedded_movies_collection = get_collection("embedded_movies") | ||||||
|
|
||||||
| # Get list of existing indexes - convert AsyncCommandCursor to list | ||||||
|
|
@@ -98,9 +99,12 @@ async def vector_search_index(): | |||||
|
|
||||||
| # Create the index | ||||||
| result = await embedded_movies_collection.create_search_index(index_definition) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we're not doing anything with this result, so we could omit it.
Suggested change
|
||||||
| print("Vector search index 'vector_index' ready to query.") | ||||||
|
|
||||||
| except Exception as e: | ||||||
| print(f"Error during vector search index setup: {str(e)}") | ||||||
| print(f"Error type: {type(e).__name__}") | ||||||
| raise RuntimeError( | ||||||
| f"Failed to create vector search index 'vector_index': {str(e)}. " | ||||||
| f"Vector search functionality will not be available. " | ||||||
| f"Please check your MongoDB Atlas configuration, ensure the cluster supports vector search, " | ||||||
| f"and verify the 'embedded_movies' collection exists with the required embedding field." | ||||||
| ) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're adding
create_error_responsehere but it looks like it's not used. Are we missing code that was meant to use it, or was this added in error?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added in error, we only use it in models.py. i will remove it