MCPcopy
hub / github.com/HKUDS/LightRAG / optimized_embedding_function

Function optimized_embedding_function

lightrag/api/lightrag_server.py:738–929  ·  view source on GitHub ↗
(
        texts, embedding_dim=None, context="document"
    )

Source from the content-addressed store, hash-verified

736 # Step 3: Create optimized embedding function (calls underlying function directly)
737 # Note: When model is None, each binding will use its own default model
738 async def optimized_embedding_function(
739 texts, embedding_dim=None, context="document"
740 ):
741 try:
742 if binding == "lollms":
743 from lightrag.llm.lollms import lollms_embed
744
745 # Get real function, skip EmbeddingFunc wrapper if present
746 actual_func = (
747 lollms_embed.func
748 if isinstance(lollms_embed, EmbeddingFunc)
749 else lollms_embed
750 )
751 # lollms embed_model is not used (server uses configured vectorizer)
752 # Only pass base_url and api_key
753 return await actual_func(texts, base_url=host, api_key=api_key)
754 elif binding == "ollama":
755 from lightrag.llm.ollama import ollama_embed
756
757 # Get real function, skip EmbeddingFunc wrapper if present
758 actual_func = (
759 ollama_embed.func
760 if isinstance(ollama_embed, EmbeddingFunc)
761 else ollama_embed
762 )
763
764 # Use pre-processed configuration if available
765 if config_cache.ollama_embedding_options is not None:
766 ollama_options = config_cache.ollama_embedding_options
767 else:
768 from lightrag.llm.binding_options import OllamaEmbeddingOptions
769
770 ollama_options = OllamaEmbeddingOptions.options_dict(args)
771
772 # Pass embed_model only if provided, let function use its default (bge-m3:latest)
773 kwargs = {
774 "texts": texts,
775 "host": host,
776 "api_key": api_key,
777 "options": ollama_options,
778 }
779 if provider_supports_asymmetric and asymmetric_opt_in:
780 kwargs["context"] = context
781 if query_prefix:
782 kwargs["query_prefix"] = query_prefix
783 if document_prefix:
784 kwargs["document_prefix"] = document_prefix
785 if model:
786 kwargs["embed_model"] = model
787 return await actual_func(**kwargs)
788 elif binding == "azure_openai":
789 from lightrag.llm.azure_openai import azure_openai_embed
790
791 actual_func = (
792 azure_openai_embed.func
793 if isinstance(azure_openai_embed, EmbeddingFunc)
794 else azure_openai_embed
795 )

Callers

nothing calls this directly

Calls 2

options_dictMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected