chroma-core / chroma-core/chroma
[Bug]: ids and docs added to db, but embeddings only appear after restart of Jupyter kernel
- Dominant language
- Rust
- Stars
- 29.3k
- Forks
- 2.5k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 38
Description
### What happened?
Running with Python 3.13.0 on an M3 Macbook
```
Macbook M3
MacOS 15.3.1
Python 3.13.0
VS Code 1.97.0
VS Code Jupyter Extension 2025.1.0
Chroma 0.6.3
```
Execute cell 1 of notebook `_t1.ipynb` running in VS Code:
```
import chromadb, os
op = os.path
curr_dir = op.abspath(os.getcwd())
chroma_path = op.join(curr_dir, 'chroma')
client = chromadb.PersistentClient(chroma_path)
```
From a separate terminal, execute the script `_t2.py`
```
import chromadb, os
op = os.path
curr_dir = op.abspath(op.dirname(__file__))
chroma_path = op.join(curr_dir, 'chroma')
client = chromadb.PersistentClient(chroma_path)
t = client.get_or_create_collection('test')
for n in range(1,6):
new_id = f'id_{n}'
new_doc = f'doc_{n}'
t.upsert(ids=[new_id], documents=[new_doc])
result = t.get(include=['documents','embeddings'])
print(f'{result["ids"] = }')
print(f'{result["documents"] = }')
print(f'{len(result["embeddings"]) = }')
print(f'{len(result["embeddings"][0]) = }')
```
Confirm the expected output in the console:
```
result["ids"] = ['id_1', 'id_2', 'id_3', 'id_4', 'id_5']
result["documents"] = ['doc_1', 'doc_2', 'doc_3', 'doc_4', 'doc_5']
len(result["embeddings"]) = 5
len(result["embeddings"][0]) = 384
```
Run cell 2 of `_t1.ipynb`:
```
t = client.get_or_create_collection('test')
result = t.get(include=['documents','embeddings'])
print(f'{result["ids"] = }')
print(f'{result["documents"] = }')
print(f'{len(result["embeddings"]) = }')
# print(f'{len(result["embeddings"][0]) = }')
result = t.query(
query_texts=['doc_1'],
include=['documents','embeddings'],
n_results=5
)
print(f"\n {'<>' * 10 } \n")
print(f'{result["ids"] = }')
print(f'{result["documents"] = }')
print(f'{len(result["embeddings"]) = }')
print(f'{len(result["embeddings"][0]) = }')
print(f'{result["embeddings"] = }')
```
Confirm that the `ids` and `documents` are there, but `embeddings` are not
```
result["ids"] = ['id_1', 'id_2', 'id_3', 'id_4', 'id_5']
result["documents"] = ['doc_1', 'doc_2', 'doc_3', 'doc_4', 'doc_5']
len(result["embeddings"]) = 0
<><><><><><><><><><>
result["ids"] = [[]]
result["documents"] = [[]]
len(result["embeddings"]) = 1
len(result["embeddings"][0]) = 0
result["embeddings"] = [array([], dtype=float64)]
```
Not only is this buggy, but it is also inconsistent.
On a separate trial, I managed to (somehow) get one embedding properly stored, even though `t.get()` was showing 5 total documents (so 4 were still missing).
The really baffling part came with `t.query()` warning that I only had 4 existing elements, despite the request for `n_results=5`.
```
result["ids"] = ['id_1', 'id_2', 'id_3', 'id_4', 'id_5']
result["documents"] = ['doc_1', 'doc_2', 'doc_3', 'doc_4', 'doc_5']
len(result["embeddings"]) = 1
len(result["embeddings"][0]) = 384
<><><><><><><><><><>
Number of requested results 5 is greater than number of elements in index 4, updating n_results = 4
result["ids"] = [['id_1', 'id_2', 'id_3', 'id_4']]
result["documents"] = [['doc_1', 'doc_2', 'doc_3', 'doc_4']]
len(result["embeddings"]) = 1
len(result["embeddings"][0]) = 1
```
This behavior occurs for image-based collections as well.
The behavior also occurs with `collection.add` (it is not specific to `collection.upsert`, as with my example).
The behavior also occurs if I create the collection for the first time in the notebook cell, as opposed to in the script (as with my current example).
If I restart the kernel and run the notebook cells again, I get the expected output:
```
result["ids"] = ['id_1', 'id_2', 'id_3', 'id_4', 'id_5']
result["documents"] = ['doc_1', 'doc_2', 'doc_3', 'doc_4', 'doc_5']
len(result["embeddings"]) = 5
<><><><><><><><><><>
result["ids"] = [['id_1', 'id_2', 'id_3', 'id_4', 'id_5']]
result["documents"] = [['doc_1', 'doc_2', 'doc_3', 'doc_4', 'doc_5']]
len(result["embeddings"]) = 1
len(result["embeddings"][0]) = 5
```
I have also confirmed that this issue **does not** exist in Google Colab.
I can run the first cell (to instantiate the persistent client), then write my `_t2.py` to the local Colab file system and call it with `%run _t2.py`, and then verify the existence of the newly inserted content (with embeddings) by running the second cell of the still-active notebook.
### Versions
Macbook M3
MacOS 15.3.1
Python 3.13.0
VS Code 1.97.0
VS Code Jupyter Extension 2025.1.0
Chroma 0.6.3
### Relevant log output
```shell
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.