Comments (1)
π Here's the PR! #20
0b2bf4e2dc
)For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).
Tip
I can email you next time I complete a pull request if you set up your email here!
Actions (click)
- β» Restart Sweep
GitHub Actionsβ
Here are the GitHub Actions logs prior to making any changes:
Sandbox logs for 91e83d1
Checking API/database.py for syntax errors... β API/database.py has no syntax errors!
1/1 βChecking API/database.py for syntax errors... β API/database.py has no syntax errors!
Sandbox passed on the latest main
, so sandbox checks will be enabled for this issue.
Step 1: π Searching
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.
Step 2: β¨οΈ Coding
Modify API/database.py with contents:
β’ Add a new method named `find_similar_vectors` in the `Database` class. This method should accept two parameters: `embedding_vector`, which is the vector for which we want to find similar vectors, and `n`, which is the number of top similar vectors to return.
β’ Inside this method, use MongoDB's aggregation framework to perform the vector similarity search. Since MongoDB does not natively support Euclidean distance calculations for vector similarity out of the box, you will need to manually implement this logic. One approach is to store the embedding vectors in a collection with a schema that includes the vector and a unique identifier. Then, use an aggregation pipeline to calculate the Euclidean distance between the input vector and the vectors stored in the database, sort the results by this calculated distance in ascending order, and limit the results to the top n entries.
β’ The method should return the top n most similar vectors from the MongoDB database.
β’ Note: This task assumes MongoDB does not have built-in support for vector similarity search based on Euclidean distance. If MongoDB introduces such a feature, the implementation should leverage that instead.--- +++ @@ -22,3 +22,31 @@ def update_one(self, collection, query, update): return self.db[collection].update_one(query, update) + def find_similar_vectors(self, collection, embedding_vector, n): + """ + Find the top n most similar vectors in the database to the given embedding_vector. + This method uses the Euclidean distance for similarity measure. + + :param collection: The MongoDB collection to search within. + :param embedding_vector: The embedding vector to find similar vectors for. + :param n: The number of top similar vectors to return. + :return: The top n most similar vectors from the MongoDB database. + """ + pipeline = [ + { + "$addFields": { + "distance": { + "$sqrt": { + "$reduce": { + "input": {"$zip": {"inputs": ["$vector", embedding_vector]}}, + "initialValue": 0, + "in": {"$add": ["$$value", {"$pow": [{"$subtract": ["$$this.0", "$$this.1"]}, 2]}]} + } + } + } + } + }, + {"$sort": {"distance": 1}}, + {"$limit": n} + ] + return list(self.db[collection].aggregate(pipeline))
- Running GitHub Actions for
API/database.py
β Edit
Check API/database.py with contents:Ran GitHub Actions for d6366ebfcc133c30f5e069c0508a89b52686ba57:
Modify API/route.py with contents:
β’ Add a new endpoint in the `route.py` file for the `recognise_face` functionality. This endpoint should accept an embedding vector and a parameter n from the user, and use the `find_similar_vectors` method from the `Database` class to find and return the top n most similar vectors.
β’ The endpoint should extract the embedding vector and the value of n from the request, call the `find_similar_vectors` method with these parameters, and return the result to the client.
β’ Ensure proper error handling is in place for cases where the input data is invalid or the database operation fails.--- +++ @@ -267,3 +267,23 @@ client.find_one_and_delete(collection, {"EmployeeCode": EmployeeCode}) return {"Message": "Successfully Deleted"} [email protected]("/recognise_face") +async def recognise_face(embedding: List[float], n: int): + """ + Recognise a face by finding the most similar face embeddings in the database. + + Args: + embedding (List[float]): The embedding vector of the face to be recognised. + n (int): The number of top similar vectors to return. + + Returns: + dict: A dictionary containing the top n most similar face embeddings. + + """ + logging.info("Recognising face") + try: + similar_faces = client.find_similar_vectors(collection, embedding, n) + return {"similar_faces": similar_faces} + except Exception as e: + logging.error(f"Error recognising face: {str(e)}") + raise HTTPException(status_code=500, detail="Internal server error")
- Running GitHub Actions for
API/route.py
β Edit
Check API/route.py with contents:Ran GitHub Actions for 7b8ca4e13c930240c7aef7d25b09dd19d42e82df:
Step 3: π Code Review
I have finished reviewing the code for completeness. I did not find errors for sweep/utility_function_for_vector_similarity_s_0cb05
.
π Latest improvements to Sweep:
- New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
- Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
- Use the GitHub issues extension for creating Sweep issues directly from your editor.
π‘ To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.
This is an automated message generated by Sweep AI.
from facerec.
Related Issues (11)
- Feature Request: New Endpoint for `recognise_face()` HOT 1
- Feature Request: Migrate Database to MongoDB Atlas and Create Interoperable Functions HOT 2
- Feature Request: Implement MongoDB Atlas Locally Using Docker [Backlog - Least Priority] HOT 1
- Feature Request: Testing for `recognise_face()` Endpoint
- Expanding the test coverage for existing endpoints
- Elaborate Documentation for API Endpoints
- Testing integration of frontend code with recognize face API endpoint
- Follow up with frontend Team
- Final Integration Testing
- Fix code scanning alert - Log Injection
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facerec.