Skip to content

Commit

Permalink
Added Vector search
Browse files Browse the repository at this point in the history
  • Loading branch information
Devasy23 committed Mar 16, 2024
1 parent c8c30fc commit a86697a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
3 changes: 2 additions & 1 deletion API/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ def vector_search(self, collection, embedding):
}
}
])
return result
result_arr = [i for i in result]
return result_arr
14 changes: 7 additions & 7 deletions API/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,17 @@ async def recognize_face(Face: UploadFile = File(...)):
"""
logging.info("Recognizing Face")
try:
img_recovered = await Face.read()
pil_image = Image.open(BytesIO(img_recovered))
image_filename = "temp.png"
pil_image.save(image_filename)
img_data = await Face.read()
with open("temp.png", "wb") as f:
f.write(img_data)

embedding = DeepFace.represent(img_path=image_filename, model_name="Facenet")
result = client2.vector_search(collection2, embedding)
embedding = DeepFace.represent(img_path="temp.png", model_name="Facenet")
result = client2.vector_search(collection2, embedding[0]['embedding'])
logging.info(f"Result: {result}")

os.remove("temp.png")
except Exception as e:
logging.error(f"Error: {e}")
os.remove("temp.png")
raise HTTPException(status_code=500, detail="Internal server error")
return Response(
content=bytes(json.dumps(result[0], default=str), "utf-8"),
Expand Down
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@
- Resolved various bugs and issues identified during the testing process.

### Removed
- Removed deprecated code and unused dependencies from the project.
- Removed deprecated code and unused dependencies from the project.

## [0.1.4] - 2024-03-16 - 23:00

### Added
- Implemented a new `recognize_Face` endpoint in [`route.py`](API/route.py). This endpoint accepts a base64 string as input, converts it into embeddings, and performs a vector search query on the MongoDB Atlas database. Changes made by @Devasy23.
- Added a new `vector_search` function in [`database.py`](API/database.py). This function performs a vector similarity search on the MongoDB Atlas database using Euclidean distance as the similarity measure. Changes made by @Devasy23.
- Updated [`index.ipynb`](index.ipynb) to include examples and usage of the new `recognize_Face` endpoint and `vector_search` function. Changes made by @Devasy23.

### Changed
- Updated the `Database` class in [`database.py`](API/database.py) to include the new `vector_search` function. Changes made by @Devasy23.

### Fixed
- Resolved various bugs and issues identified during the implementation and testing of the new features. Fixes made by @Devasy23.
46 changes: 44 additions & 2 deletions Vector Search/index.ipynb → index.ipynb

Large diffs are not rendered by default.

0 comments on commit a86697a

Please sign in to comment.