Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions knowledge_mcp/openai_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,17 @@ async def vision_model_func(prompt, system_prompt=None, history_messages=[], ima
)

async def openai_embedding_func(texts: list[str]) -> np.ndarray:
embedding_model = Config.get_instance().lightrag.embedding.model_name

# Call the OpenAI embed function with all the parameters
return await openai_embed(
texts=texts,
model=embedding_model,
api_key=Config.get_instance().lightrag.embedding.api_key,
base_url=Config.get_instance().lightrag.embedding.api_base,
)
# Call the OpenAI-compatible embeddings endpoint directly instead of going
# through lightrag.llm.openai.openai_embed, which is decorated with
# @wrap_embedding_func_with_attrs(embedding_dim=1536) and therefore pins
# the dimension to OpenAI text-embedding-3-*. Going direct lets the caller
# use any model (Ollama bge-m3 at 1024, mxbai-embed-large, etc.); the
# EmbeddingFunc wrapper below still validates the configured dimension.
cfg = Config.get_instance().lightrag.embedding
from openai import AsyncOpenAI
client = AsyncOpenAI(api_key=cfg.api_key, base_url=cfg.api_base)
response = await client.embeddings.create(model=cfg.model_name, input=texts)
return np.array([item.embedding for item in response.data])

# Wrap the embedding function with the correct attributes from config
embedding_func = EmbeddingFunc(
Expand Down
10 changes: 7 additions & 3 deletions knowledge_mcp/rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ async def create_rag_instance(self, kb_name: str) -> RAGAnything:
working_dir=str(kb_path),
llm_model_func=llm_func,
llm_model_kwargs=llm_kwargs,
llm_model_name=llm_config.model_name,
llm_model_max_token_size=llm_model_max_tokens,
llm_model_name=llm_config.model_name,
embedding_func=embed_func,
embedding_cache_config={
"enabled": cache_config.enabled,
Expand Down Expand Up @@ -248,7 +247,12 @@ async def query(self, kb_name: str, query_text: str, **kwargs: Any) -> Any:

# Ensure 'description' is not passed as a query param
final_query_params.pop("description", None)


# Filter out kwargs that older per-KB configs may still emit but
# which were removed from lightrag-hku's QueryParam in 1.4.x.
for stale_kwarg in ("ids", "model_func", "chunk_top_k", "enable_rerank"):
final_query_params.pop(stale_kwarg, None)

# Handle user_prompt: only include if not empty
user_prompt_value = final_query_params.get('user_prompt', '')
if not (user_prompt_value and user_prompt_value.strip()):
Expand Down