Error loading model from Module 2: Agentic Search - Assignment assemblig the coding agent

Hi, first, thank you for your course.
I just got a problem loading the model ‘all-MiniLM-L6-v2’ with the setup_collection function from helper_utils.py file.
Here the stack trace:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[5], line 4
      1 # Embedding function used to index and query the collection (same model as the labs)
      2 EMBEDDING_FUNCTION = helper_utils.setup_local_embedding_function(model_name="all-MiniLM-L6-v2")
----> 4 COLLECTION = helper_utils.setup_collection(repo_path="feedback_app", embedding_function=EMBEDDING_FUNCTION)

File ~/work/helper_utils.py:496, in setup_collection(repo_path, collection_name, chroma_path, embedding_function)
    493 global OPENAI_CLIENT
    494 OPENAI_CLIENT = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
--> 496 return load_or_create_collection(
    497     collection_name=collection_name,
    498     repo_path=repo_path,
    499     persist_dir=chroma_path,
    500     embedding_function=embedding_function,
    501 )

File ~/work/helper_utils.py:466, in load_or_create_collection(collection_name, repo_path, persist_dir, batch_size, embedding_function, ignore_dirs, exclude_files)
    463     _add_batch(coll, buffer)
    465 print(f"Collection '{collection_name}' ready — {coll.count()} chunks ingested.")
--> 466 return _pair_with_sparse_index(coll)

File ~/work/helper_utils.py:394, in _pair_with_sparse_index(collection)
    391 stored = collection.get(include=["documents"])
    393 # Construct the sparse index by encoding the stored chunks
--> 394 sparse_index = BM25SparseIndex(chunk_ids=stored["ids"], chunks=stored["documents"])
    396 # Report the indexed vocabulary size
    397 print(f"     Sparse index ready: {len(sparse_index.inverted_index)} unique terms indexed.")

File ~/work/helper_utils.py:234, in BM25SparseIndex.__init__(self, chunk_ids, chunks)
    231 self.inverted_index = defaultdict(list)
    233 # Encode all chunks into sparse vectors in one batch
--> 234 sparse_vectors = self.encoder(chunks)
    236 # Iterate through each chunk and its computed sparse vector
    237 for chunk_id, vector in zip(chunk_ids, sparse_vectors):
    238     # Unpack the term indices and weights from the sparse vector

File /usr/local/lib/python3.11/site-packages/chromadb/api/types.py:1454, in SparseEmbeddingFunction.__init_subclass__.<locals>.__call__(self, input)
   1452 result = call(self, input)
   1453 assert result is not None
-> 1454 return validate_sparse_vectors(cast(SparseVectors, result))

File /usr/local/lib/python3.11/site-packages/chromadb/api/types.py:1354, in validate_sparse_vectors(vectors)
   1350     raise ValueError(
   1351         f"Expected sparse vectors to be a list, got {type(vectors).__name__}"
   1352     )
   1353 if len(vectors) == 0:
-> 1354     raise ValueError(
   1355         f"Expected sparse vectors to be a non-empty list, got {len(vectors)} sparse vectors"
   1356     )
   1357 for i, vector in enumerate(vectors):
   1358     if not isinstance(vector, SparseVector):

ValueError: Expected sparse vectors to be a non-empty list, got 0 sparse vectors

I try to delete the model directory and redownload the model from HuggingFace but it seems to be an error when encoding all chunks into sparse vectors in one batch.

Have a good day

Hi @Francois_BIGOT,

The all-MiniLM-L6-v2 model actually loaded fine (line 2 succeeded). The error on line 4 happens because setup_collection ingested 0 chunks from feedback_app, so BM25SparseIndex received an empty list (chunks=[]) and ChromaDB rejected it with got 0 sparse vectors.

You can confirm this right above the traceback, where helper_utils.py should have printed 0 chunks ingested. That happens when feedback_app is missing or empty in your working directory (~/work).

Try these checks in order:

  1. Run !ls -la and !ls -la feedback_app in a cell to verify that feedback_app exists and actually contains source files.
  2. Make sure no earlier setup cell in the notebook (such as cloning or unpacking feedback_app) was skipped. If an interrupted run left an empty feedback_app folder behind, setup helpers that check os.path.exists will skip re-creating it, so delete the empty folder (and any partial Chroma DB folder) and re-run from the first cell.
  3. If feedback_app is supposed to come pre-packaged in the lab workspace and is missing, restore it via Lab Help → Get Latest Version, then use Kernel → Restart & Clear Output and run the cells from the top.

If feedback_app already has files in it and you still get this error, reply with the output of !ls -la feedback_app and the line printed right before the traceback.