Spaces:
Sleeping
Sleeping
Download src/embeddings.py from ABDRauf/dynamic-rag-fastapi: direct link, hf CLI and curl.
- Browser
- Download file 803 Bytes
-
https://huggingface.co/spaces/ABDRauf/dynamic-rag-fastapi/resolve/main/src/embeddings.py
- Command line
-
hf download hf://spaces/ABDRauf/dynamic-rag-fastapi/src/embeddings.py
-
curl -L -o embeddings.py https://huggingface.co/spaces/ABDRauf/dynamic-rag-fastapi/resolve/main/src/embeddings.py
803 Bytes
| from langchain_huggingface import HuggingFaceEmbeddings | |
| from src.logger import logger | |
| def get_embeddings(model_name: str = "all-MiniLM-L6-v2"): | |
| """ | |
| Initializes and returns the HuggingFace embedding model. | |
| This model translates text chunks into mathematical vectors. | |
| """ | |
| logger.info(f"Initializing embedding model: {model_name}") | |
| try: | |
| # Initialize the HuggingFace embeddings model | |
| embeddings = HuggingFaceEmbeddings(model_name=model_name) | |
| logger.info("Successfully loaded embedding model.") | |
| # Return the embedding object so ChromaDB can use it | |
| return embeddings | |
| except Exception as e: | |
| logger.error(f"Failed to initialize embeddings: {str(e)}", exc_info=True) | |
| raise e |