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