I’m getting stuck with a Flask RAG setup and could use some help. I’m running into problems with FastEmbedEmbeddings where the _model attribute seems to be causing issues.
First I got this validation error:
pydantic.v1.error_wrappers.ValidationError: 1 validation error for FastEmbedEmbeddings _model extra fields not permitted (type=value_error.extra)
I tried fixing it by changing the Config class:
class CustomEmbedModel(BaseModel, Embeddings):
# Various properties defined here
_embedding_model: Any # private attribute
class Config:
# Changed from extra = Extra.forbid
extra = Extra.ignore
This change made the server start but now I get a different error when trying to process documents:
AttributeError: 'FastEmbedEmbeddings' object has no attribute '_model'
The error happens in these methods:
# In document embedding:
embedding_results = self._embedding_model.embed(document_texts)
# In query processing:
query_results: np.ndarray = next(self._embedding_model.query_embed(query_text))
Could this be a version compatibility issue? I’m using pydantic 2.8.2, pydantic_core 2.20.1, and fastembed 0.3.3. I also had some package installation issues earlier where I used sudo pip install which might have messed things up.
fastembed 0.3.3 probably doesn’t work with pydantic 2.x yet. I’ve seen this before - the _model attribute doesn’t get set during init. Try a fresh venv, install fastembed first, then let it handle its own pydantic dependencies. Fixed it for me when mixed versions were causing issues.
The AttributeError happens because extra = Extra.ignore stops the _model attribute from initializing properly when you create the object. You’re suppressing the validation error, so the FastEmbed model never gets created. I hit something similar mixing langchain versions with different embedding classes. The real problem is FastEmbedEmbeddings needs specific initialization parameters that aren’t passing through correctly with your custom wrapper. Try initializing FastEmbedEmbeddings directly without the custom BaseModel wrapper first - see if it works standalone. If it does, the issue’s in how you’re inheriting and setting up the class structure. You might need to explicitly call the parent constructor or handle the private attribute initialization in your __init__ method. That sudo pip install definitely didn’t help either - mixed dependencies cause weird attribute resolution issues that are a pain to debug.
You’ve encountered a common compatibility issue between pydantic versions. The error message referencing pydantic.v1.error_wrappers.ValidationError indicates that your setup is using a mixed pydantic environment, as FastEmbedEmbeddings is intended for pydantic v1 while you are currently on v2. Rather than modifying the base class config, I recommend downgrading your pydantic version with the command: pip install "pydantic<2.0" and see if that resolves your issue. The use of sudo for installations can create dependency conflicts and break your environment. It’s advisable to work within a new virtual environment, ensuring that no global packages interfere. Additionally, verify if the used version of fastembed supports pydantic 2.x, and consider updating if compatible versions are available.
Yeah, pydantic version issues are a pain. But honestly? There’s a way cleaner approach than fighting these dependency conflicts.
Hit the same wall building document pipelines at work. Instead of wrestling with versions and manual configs, I just automated the whole RAG workflow.
You need something that handles document ingestion, embedding generation, and queries without babysitting all the moving parts. All those embedding conflicts, Flask routes, and document processing headaches? Automate it in one workflow.
Built exactly this - documents get processed automatically, embedded with the best model available, stored right, then queried through a clean API. No more pydantic wrestling or manual attribute fixes.
Best part? Set triggers for doc updates, auto-reprocess when needed, scale embedding generation with load. You get proper error handling and logging without building it yourself.
Skip fixing these dependencies one by one. Automate the whole pipeline and your RAG system runs smooth without touching pydantic configs or attribute errors.
Check out https://latenode.com for this kind of automated document workflow.