<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Unable to add dependencies to mlflow.langchain.log_model in Generative AI</title>
    <link>https://community.databricks.com/t5/generative-ai/unable-to-add-dependencies-to-mlflow-langchain-log-model/m-p/82286#M336</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm doing this-&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with mlflow.start_run(run_name="run1"):
  logged_chain_info = mlflow.langchain.log_model(
        #   lc_model=os.path.join(os.getcwd(), 'full_chain'), this doesnt work too  
          lc_model='/Workspace/Users/{user_name}/exp/deploy_chain.py',
          model_config="/Workspace/Users/{user_name}/exp/chain_config.yaml", 
          artifact_path="exp_1_artifact",
    
          input_example=input_example,
          example_no_conversion=True,
          code_paths=["/Workspace/Users/{user_name}/exp/example_docs.py"]

      )&lt;/LI-CODE&gt;&lt;P&gt;But when I do import example_docs in deploy_chain.py it says module not found when I run the above code.&lt;/P&gt;&lt;P&gt;Similarly,&lt;/P&gt;&lt;P&gt;If I try to add a pdf/image file in code_paths and try to access it using relative path it fails on the mlflow run step, If I give absolute path, it fails while serving the endpoint (file not found).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should I add dependent files to this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Aug 2024 22:32:24 GMT</pubDate>
    <dc:creator>yashshingvi</dc:creator>
    <dc:date>2024-08-07T22:32:24Z</dc:date>
    <item>
      <title>Unable to add dependencies to mlflow.langchain.log_model</title>
      <link>https://community.databricks.com/t5/generative-ai/unable-to-add-dependencies-to-mlflow-langchain-log-model/m-p/82286#M336</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm doing this-&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with mlflow.start_run(run_name="run1"):
  logged_chain_info = mlflow.langchain.log_model(
        #   lc_model=os.path.join(os.getcwd(), 'full_chain'), this doesnt work too  
          lc_model='/Workspace/Users/{user_name}/exp/deploy_chain.py',
          model_config="/Workspace/Users/{user_name}/exp/chain_config.yaml", 
          artifact_path="exp_1_artifact",
    
          input_example=input_example,
          example_no_conversion=True,
          code_paths=["/Workspace/Users/{user_name}/exp/example_docs.py"]

      )&lt;/LI-CODE&gt;&lt;P&gt;But when I do import example_docs in deploy_chain.py it says module not found when I run the above code.&lt;/P&gt;&lt;P&gt;Similarly,&lt;/P&gt;&lt;P&gt;If I try to add a pdf/image file in code_paths and try to access it using relative path it fails on the mlflow run step, If I give absolute path, it fails while serving the endpoint (file not found).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should I add dependent files to this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 22:32:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/unable-to-add-dependencies-to-mlflow-langchain-log-model/m-p/82286#M336</guid>
      <dc:creator>yashshingvi</dc:creator>
      <dc:date>2024-08-07T22:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to add dependencies to mlflow.langchain.log_model</title>
      <link>https://community.databricks.com/t5/generative-ai/unable-to-add-dependencies-to-mlflow-langchain-log-model/m-p/138471#M1374</link>
      <description>&lt;P class="qt3gz91 paragraph"&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/115248"&gt;@yashshingvi&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P class="qt3gz91 paragraph"&gt;Thanks for the details—this is a common gotcha with MLflow “models from code.”&lt;/P&gt;
&lt;H3 class="_7uu25p0 qt3gz9c _7pq7t612 heading3 _7uu25p1"&gt;Why your imports fail&lt;/H3&gt;
&lt;UL class="qt3gz97 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;&lt;STRONG&gt;code_paths&lt;/STRONG&gt; are only added to &lt;CODE class="qt3gz9f"&gt;sys.path&lt;/CODE&gt; when the model is loaded (for inference/serving), not while the driver is executing &lt;CODE class="qt3gz9f"&gt;mlflow.langchain.log_model(...)&lt;/CODE&gt; to log the model.&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;In the &lt;STRONG&gt;code-based logging&lt;/STRONG&gt; flow, MLflow runs your &lt;CODE class="qt3gz9f"&gt;lc_model&lt;/CODE&gt; file (deploy_chain.py) during logging; any imports inside that file must already be importable in the current notebook/cluster environment at logging time.&lt;/LI&gt;
&lt;/UL&gt;
&lt;H3 class="_7uu25p0 qt3gz9c _7pq7t612 heading3 _7uu25p1"&gt;Make Python modules importable at logging time&lt;/H3&gt;
&lt;P class="qt3gz91 paragraph"&gt;Pick one of these:&lt;/P&gt;
&lt;UL class="qt3gz97 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;Add the directory containing your helper modules (example_docs.py) to &lt;CODE class="qt3gz9f"&gt;sys.path&lt;/CODE&gt; before calling &lt;CODE class="qt3gz9f"&gt;log_model&lt;/CODE&gt;:&lt;/P&gt;
&lt;DIV class="go8b9g1 _7pq7t6cj" data-ui-element="code-block-container"&gt;
&lt;PRE&gt;&lt;CODE class="markdown-code-python qt3gz9e hljs language-python _1ymogdh2"&gt;&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; sys
sys.path.append(&lt;SPAN class="hljs-string"&gt;"/Workspace/Users/&amp;lt;user&amp;gt;/exp"&lt;/SPAN&gt;)  &lt;SPAN class="hljs-comment"&gt;# folder that contains example_docs.py&lt;/SPAN&gt;

&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; mlflow

&lt;SPAN class="hljs-keyword"&gt;with&lt;/SPAN&gt; mlflow.start_run(run_name=&lt;SPAN class="hljs-string"&gt;"run1"&lt;/SPAN&gt;):
    logged_chain_info = mlflow.langchain.log_model(
        lc_model=&lt;SPAN class="hljs-string"&gt;"/Workspace/Users/&amp;lt;user&amp;gt;/exp/deploy_chain.py"&lt;/SPAN&gt;,
        model_config=&lt;SPAN class="hljs-string"&gt;"/Workspace/Users/&amp;lt;user&amp;gt;/exp/chain_config.yaml"&lt;/SPAN&gt;,
        artifact_path=&lt;SPAN class="hljs-string"&gt;"exp_1_artifact"&lt;/SPAN&gt;,
        input_example=input_example,
        example_no_conversion=&lt;SPAN class="hljs-literal"&gt;True&lt;/SPAN&gt;,
        &lt;SPAN class="hljs-comment"&gt;# include the whole directory so it’s available at load/serve time too&lt;/SPAN&gt;
        code_paths=[&lt;SPAN class="hljs-string"&gt;"/Workspace/Users/&amp;lt;user&amp;gt;/exp"&lt;/SPAN&gt;],
    )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;P class="qt3gz91 paragraph"&gt;This ensures &lt;CODE class="qt3gz9f"&gt;import example_docs&lt;/CODE&gt; inside deploy_chain.py resolves during the logging step, and the directory is also packaged for serving.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;Preferably, &lt;STRONG&gt;use a Databricks Repo&lt;/STRONG&gt; and install your package in the logging environment:&lt;/P&gt;
&lt;DIV class="go8b9g1 _7pq7t6cj" data-ui-element="code-block-container"&gt;
&lt;PRE&gt;&lt;CODE class="markdown-code-python qt3gz9e hljs language-python _1ymogdh2"&gt;&lt;SPAN class="hljs-comment"&gt;# One-time per cluster, or in your notebook before log_model&lt;/SPAN&gt;
%pip install -e /Workspace/Repos/&amp;lt;your_repo&amp;gt;/  &lt;SPAN class="hljs-comment"&gt;# has pyproject.toml/setup.py&lt;/SPAN&gt;

&lt;SPAN class="hljs-comment"&gt;# then log as usual&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;P class="qt3gz91 paragraph"&gt;This is the most reliable way to satisfy imports both at logging and serving time, as MLflow will capture and restore package dependencies.&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Sources:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://docs.databricks.com/aws/en/mlflow/log-model-dependencies" target="_blank"&gt;https://docs.databricks.com/aws/en/mlflow/log-model-dependencies&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://docs.databricks.com/aws/en/generative-ai/agent-framework/log-agent" target="_blank"&gt;https://docs.databricks.com/aws/en/generative-ai/agent-framework/log-agent&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://docs.databricks.com/aws/en/mlflow/models" target="_blank"&gt;https://docs.databricks.com/aws/en/mlflow/models&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 10 Nov 2025 20:25:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/unable-to-add-dependencies-to-mlflow-langchain-log-model/m-p/138471#M1374</guid>
      <dc:creator>stbjelcevic</dc:creator>
      <dc:date>2025-11-10T20:25:57Z</dc:date>
    </item>
  </channel>
</rss>

