Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit ab3d05b

Browse files
authored
Multimodal (#157)
* Docs and Ordering * Migration notes, typo
1 parent c4d24d2 commit ab3d05b

11 files changed

+193
-10
lines changed

docs/about.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 5
2+
sidebar_position: 15
33
---
44

55
# 👽 About

docs/api-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 5
2+
sidebar_position: 6
33
title: "📖 API Cheatsheet"
44
---
55

docs/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 10
2+
sidebar_position: 14
33
title: "🍻 Contributing"
44
---
55

docs/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 8
2+
sidebar_position: 9
33
title: "☁️ Deployment"
44
---
55

docs/integrations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 7
2+
sidebar_position: 8
33
---
44

55
# 🔌 Integrations

docs/migration.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 7
2+
sidebar_position: 10
33
---
44

55
# ✈️ Migration
@@ -22,6 +22,38 @@ We will aim to provide:
2222

2323
## Migration Log
2424

25+
### Migration to 0.4.16 - November 7, 2023
26+
27+
This release adds support for multi-modal embeddings, with an accompanying change to the definitions of `EmbeddingFunction`.
28+
This change mainly affects users who have implemented their own `EmbeddingFunction` classes. If you are using Chroma's built-in embedding functions, you do not need to take any action.
29+
30+
**EmbeddingFunction**
31+
32+
Previously, `EmbeddingFunction`s were defined as:
33+
34+
```python
35+
class EmbeddingFunction(Protocol):
36+
def __call__(self, texts: Documents) -> Embeddings:
37+
...
38+
```
39+
40+
After this update, `EmbeddingFunction`s are defined as:
41+
42+
```python
43+
Embeddable = Union[Documents, Images]
44+
D = TypeVar("D", bound=Embeddable, contravariant=True)
45+
46+
class EmbeddingFunction(Protocol[D]):
47+
def __call__(self, input: D) -> Embeddings:
48+
...
49+
```
50+
51+
The key differences are:
52+
- `EmbeddingFunction` is now generic, and takes a type parameter `D` which is a subtype of `Embeddable`. This allows us to define `EmbeddingFunction`s which can embed multiple modalities.
53+
- `__call__` now takes a single argument, `input`, to support data of any type `D`. The `texts` argument has been removed.
54+
55+
56+
2557
### Migration from >0.4.0 to 0.4.0 - July 17, 2023
2658

2759
What's new in this version?

docs/multi-modal.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
sidebar_position: 5
3+
title: "🖼️ Multi-modal"
4+
---
5+
6+
# 🖼️ Multi-modal
7+
8+
import Tabs from '@theme/Tabs';
9+
import TabItem from '@theme/TabItem';
10+
11+
<div class="select-language">Select a language</div>
12+
13+
<Tabs queryString groupId="lang">
14+
<TabItem value="py" label="Python"></TabItem>
15+
<TabItem value="js" label="JavaScript"></TabItem>
16+
</Tabs>
17+
18+
---
19+
20+
<Tabs queryString groupId="lang" className="hideTabSwitcher">
21+
<TabItem value="py" label="Python">
22+
23+
Chroma supports multimodal collections, i.e. collections which can store, and can be queried by, multiple modalities of data.
24+
25+
## Multi-modal Embedding Functions
26+
27+
Chroma supports multi-modal embedding functions, which can be used to embed data from multiple modalities into a single embedding space.
28+
29+
Chroma has the OpenCLIP embedding function built in, which supports both text and images.
30+
31+
```python
32+
from chromadb.utils.embedding_functions import OpenCLIPEmbeddingFunction
33+
embedding_function = OpenCLIPEmbeddingFunction()
34+
```
35+
36+
## Data Loaders
37+
38+
Chroma supports data loaders, for storing and querying with data stored outside Chroma itself, via URI. Chroma will not store this data, but will instead store the URI, and load the data from the URI when needed.
39+
40+
Chroma has an data loader for loading images from a filesystem built in.
41+
42+
```python
43+
from chromadb.utils.data_loaders import ImageDataLoader
44+
data_loader = ImageDataLoader()
45+
```
46+
47+
## Multi-modal Collections
48+
49+
You can create a multi-modal collection by passing in a multi-modal embedding function. In order to load data from a URI, you must also pass in a data loader.
50+
51+
```python
52+
import chromadb
53+
54+
client = chromadb.Client()
55+
56+
collection = client.create_collection(
57+
name='multimodal_collection',
58+
embedding_function=embedding_function,
59+
data_loader=image_loader)
60+
61+
```
62+
63+
### Adding data
64+
65+
You can add data to a multi-modal collection by specifying the data modality. For now, images are supported:
66+
67+
```python
68+
collection.add(
69+
ids=['id1', 'id2', 'id3'],
70+
images=[...] # A list of numpy arrays representing images
71+
)
72+
```
73+
74+
Note that Chroma will not store the data for you, and you will have to maintain a mapping from IDs to data yourself.
75+
76+
However, you can use Chroma in combination with data stored elsewhere, by adding it via URI. Note that this requires that you have specified a data loader when creating the collection.
77+
78+
```python
79+
collection.add(
80+
ids=['id1', 'id2', 'id3'],
81+
uris=[...] # A list of strings representing URIs to data
82+
)
83+
```
84+
85+
Since the embedding function is multi-modal, you can also add text to the same collection:
86+
87+
```python
88+
collection.add(
89+
ids=['id4', 'id5', 'id6'],
90+
texts=["This is a document", "This is another document", "This is a third document"]
91+
)
92+
```
93+
94+
### Querying
95+
96+
You can query a multi-modal collection with any of the modalities that it supports. For example, you can query with images:
97+
98+
```python
99+
results = collection.query(
100+
query_images=[...] # A list of numpy arrays representing images
101+
)
102+
```
103+
104+
Or with text:
105+
106+
```python
107+
results = collection.query(
108+
query_texts=["This is a query document", "This is another query document"]
109+
)
110+
```
111+
112+
If a data loader is set for the collection, you can also query with URIs which reference data stored elsewhere of the supported modalities:
113+
114+
```python
115+
results = collection.query(
116+
query_uris=[...] # A list of strings representing URIs to data
117+
)
118+
```
119+
120+
Additionally, if a data loader is set for the collection, and URIs are available, you can include the data in the results:
121+
122+
```python
123+
results = collection.query(
124+
query_images=[...], # # list of numpy arrays representing images
125+
includes=['data']
126+
)
127+
```
128+
129+
This will automatically call the data loader for any available URIs, and include the data in the results. `uris` are also available as an `includes` field.
130+
131+
### Updating
132+
133+
You can update a multi-modal collection by specifying the data modality, in the same way as `add`. For now, images are supported:
134+
135+
```python
136+
collection.update(
137+
ids=['id1', 'id2', 'id3'],
138+
images=[...] # A list of numpy arrays representing images
139+
)
140+
```
141+
142+
Note that a given entry with a specific ID can only have one associated modality at a time. Updates will over-write the existing modality, so for example, an entry which originally has corresponding text and updated with an image, will no longer have that text after an update with images.
143+
144+
</TabItem>
145+
<TabItem value="js" label="JavaScript">
146+
147+
Support for multi-modal retrieval for Chroma's JavaScript client is coming soon!
148+
149+
</TabItem>
150+
151+
</Tabs>

docs/observability.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 8
2+
sidebar_position: 11
33
title: "👀 Observability"
44
---
55

docs/roadmap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 9
2+
sidebar_position: 13
33
title: "🛣️ Roadmap"
44
---
55

docs/telemetry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 8
2+
sidebar_position: 12
33
title: "📏 Telemetry"
44
---
55

docs/troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 10
2+
sidebar_position: 7
33
title: "🔍 Troubleshooting"
44
---
55

0 commit comments

Comments
 (0)