Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: resolve double decoration in embedding functions for OpenRouter compatibility

Laksh-star4494ffca1bff
diff --git a/src/knowledge/initializer.py b/src/knowledge/initializer.py
index 6ffa0bd86..e8ca3a3e9 100644
--- a/src/knowledge/initializer.py
+++ b/src/knowledge/initializer.py
@@ -281,10 +281,14 @@ class KnowledgeBaseInitializer:
embedding_cfg = self.embedding_cfg
embedding_api_key = embedding_cfg["api_key"] or self.api_key
embedding_base_url = embedding_cfg["base_url"] or self.base_url
+
+ # CRITICAL: Use openai_embed.func to avoid double decoration
+ # openai_embed is already decorated with @wrap_embedding_func_with_attrs
+ # We need to access the unwrapped function to prevent dimension mismatch
embedding_func = EmbeddingFunc(
embedding_dim=embedding_cfg["dim"],
max_token_size=embedding_cfg["max_tokens"],
- func=lambda texts: openai_embed(
+ func=lambda texts: openai_embed.func(
texts,
model=embedding_cfg["model"],
api_key=embedding_api_key,
diff --git a/src/tools/rag_tool.py b/src/tools/rag_tool.py
index 98250e8b1..2e3e722a5 100644
--- a/src/tools/rag_tool.py
+++ b/src/tools/rag_tool.py
@@ -199,10 +199,13 @@ async def rag_search(
return llm_model_func(prompt, system_prompt, history_messages, **kwargs)
# Define embedding function
+ # CRITICAL: Use openai_embed.func to avoid double decoration
+ # openai_embed is already decorated with @wrap_embedding_func_with_attrs
+ # We need to access the unwrapped function to prevent dimension mismatch
embedding_func = EmbeddingFunc(
embedding_dim=embedding_dim,
max_token_size=embedding_max_tokens,
- func=lambda texts: openai_embed(
+ func=lambda texts: openai_embed.func(
texts,
model=embedding_model,
api_key=embedding_api_key,