Skip to content

[Bug]: PyInstaller support for CLI app fails due to dynamic imports and EmbeddingFunction validation #4092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
memelab74 opened this issue Mar 26, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@memelab74
Copy link

What happened?

Summary

I'm building a CLI-based chatbot prototype using ChromaDB with SentenceTransformers and a persistent local database. To make it shareable with non-technical users, I attempted to package it using PyInstaller — but ran into significant issues due to dynamic imports and embedding function validation in ChromaDB (v0.4.16+).

This issue documents those findings and may be helpful to others attempting similar packaging strategies. Yes, AI helped me write this, and I hope it's helpful to you.


Environment

  • OS: macOS (ARM64, Python 3.12.9 via pyenv)
  • ChromaDB: 0.4.16
  • Backend: PersistentClient(path="./chroma_db") (SQLite)
  • Embedding: Custom EmbeddingFunction using sentence-transformers
  • Packager: PyInstaller 6.5.0
  • App: CLI chatbot that queries multiple collections

Problem 1: EmbeddingFunction interface mismatch

Error:

ValueError: Expected EmbeddingFunction.__call__ to have the following signature: odict_keys(['self', 'input']), got odict_keys(['self', 'args', 'kwargs'])

🔧 Fix: Wrapped model like this:

class ChromaEmbeddingFunction(EmbeddingFunction):
    def __init__(self, model):
        self.model = model

    def __call__(self, input):
        if isinstance(input, str):
            input = [input]
        return self.model.encode(input).tolist()

Problem 2: Dynamic import errors in PyInstaller build

Each PyInstaller run failed with a new error. Examples:

  • ModuleNotFoundError: No module named 'chromadb.telemetry.product.posthog'
  • ModuleNotFoundError: No module named 'chromadb.segment.impl.metadata.sqlite'
  • ModuleNotFoundError: No module named 'chromadb.execution.executor.local'
  • ...and several others

🔧 Fix: Required a large list of hiddenimports in the .spec file:

hiddenimports = [
    'chromadb.telemetry.product.posthog',
    'chromadb.api.segment',
    'chromadb.db.impl',
    'chromadb.db.impl.sqlite',
    'chromadb.migrations',
    'chromadb.migrations.embeddings_queue',
    'chromadb.segment.impl.manager',
    'chromadb.segment.impl.manager.local',
    'chromadb.segment.impl.metadata',
    'chromadb.segment.impl.metadata.sqlite',
    'chromadb.segment.impl.vector',
    'chromadb.execution.executor.local',
    'chromadb.quota.simple_quota_enforcer',
    'chromadb.rate_limit.simple_rate_limit',
    'analytics',  # dependency for posthog
]

Suggestions

  • 📘 Documentation: It would be helpful to document Chroma’s reliance on dynamic imports and what embedding/segment modules are required for local use.
  • ⚙️ Static mode?: Consider offering a “static embedding + sqlite” mode that avoids lazy loading or plugin discovery — ideal for CLI and embedded apps.

Final Notes

If helpful, I'm happy to share:

  • A working CLI demo script
  • The full .spec file
  • Repro steps and final packaged CLI tool

Thanks for the great work — ChromaDB is fantastic for local, lightweight AI apps. Just wanted to surface some of the rough edges when packaging for offline users.

Versions

  • OS: macOS (ARM64, Python 3.12.9 via pyenv)
  • ChromaDB: 0.4.16
  • Backend: PersistentClient(path="./chroma_db") (SQLite)
  • Embedding: Custom EmbeddingFunction using sentence-transformers
  • Packager: PyInstaller 6.5.0
  • App: CLI chatbot that queries multiple collections

Relevant log output

@memelab74 memelab74 added the bug Something isn't working label Mar 26, 2025
@jeffchuber
Copy link
Contributor

Chroma is now on 1.0.x - can you give that a shot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants