ChromaDB

Here is a list of all available ChromaDB procedures, note that the list and the signature procedures are consistent with the others, like the Qdrant ones:

name description

apoc.vectordb.chroma.info(hostOrKey, collection, $config)

Get information about the specified existing collection or throws an error 500 if it does not exist

apoc.vectordb.chroma.createCollection(hostOrKey, collection, similarity, size, $config)

Creates a collection, with the name specified in the 2nd parameter, and with the specified similarity and size. The default endpoint is <hostOrKey param>/api/v1/collections.

apoc.vectordb.chroma.deleteCollection(hostOrKey, collection, $config)

Deletes a collection with the name specified in the 2nd parameter. The default endpoint is <hostOrKey param>/api/v1/collections/<collection param>.

apoc.vectordb.chroma.upsert(hostOrKey, collection, vectors, $config)

Upserts, in the collection with the name specified in the 2nd parameter, the vectors [{id: 'id', vector: '<vectorDb>', medatada: '<metadata>'}]. The default endpoint is <hostOrKey param>/api/v1/collections/<collection param>/upsert.

apoc.vectordb.chroma.delete(hostOrKey, collection, ids, $config)

Deletes the vectors with the specified ids. The default endpoint is <hostOrKey param>/api/v1/collections/<collection param>/delete.

apoc.vectordb.chroma.get(hostOrKey, collection, ids, $config)

Gets the vectors with the specified ids. The default endpoint is <hostOrKey param>/api/v1/collections/<collection param>/get.

apoc.vectordb.chroma.query(hostOrKey, collection, vector, filter, limit, $config)

Retrieve closest vectors from the defined vector, limit of results, in the collection with the name specified in the 2nd parameter. The default endpoint is <hostOrKey param>/api/v1/collections/<collection param>/query.

apoc.vectordb.chroma.getAndUpdate(hostOrKey, collection, ids, $config)

Gets the vectors with the specified ids, and optionally creates/updates neo4j entities. The default endpoint is <hostOrKey param>/api/v1/collections/<collection param>/get.

apoc.vectordb.chroma.queryAndUpdate(hostOrKey, collection, vector, filter, limit, $config)

Retrieve closest vectors from the defined vector, limit of results, in the collection with the name specified in the 2nd parameter, and optionally creates/updates neo4j entities. The default endpoint is <hostOrKey param>/api/v1/collections/<collection param>/query.

where the 1st parameter can be a key defined by the apoc config apoc.chroma.<key>.host=myHost. With hostOrKey=null, the default is 'http://localhost:8000'.

Examples

Get collection info (it leverages this API)
CALL apoc.vectordb.chroma.info(hostOrKey, 'test_collection', {<optional config>})
Table 1. Example results
value

{"name": "test_collection", "metadata": {"size": 4, "hnsw:space": "cosine"}, "database": "default_database", "id": "74ebe008-1ccb-4d3d-8c5d-cdd7cfa526c2", "tenant": "default_tenant"}

Create a collection (it leverages this API)
CALL apoc.vectordb.chroma.createCollection($host, 'test_collection', 'Cosine', 4, {<optional config>})
Table 2. Example results
name metadata database id tenant

test_collection

{"size": 4, "hnsw:space": "cosine"}

default_database

9c046861-f46f-417d-bd01-ca8c9f99aee5

default_tenant

Delete a collection (it leverages this API)
CALL apoc.vectordb.chroma.deleteCollection($host, '<collection_id>', {<optional config>})

which returns an empty result.

Upsert vectors (it leverages this API)
CALL apoc.vectordb.qdrant.upsert($host, '<collection_id>',
    [
        {id: 1, vector: [0.05, 0.61, 0.76, 0.74], metadata: {city: "Berlin", foo: "one"}, text: 'ajeje'},
        {id: 2, vector: [0.19, 0.81, 0.75, 0.11], metadata: {city: "London", foo: "two"}, text: 'brazorf'}
    ],
    {<optional config>})

which returns an empty result.

Get vectors (it leverages this API)
CALL apoc.vectordb.chroma.get($host, '<collection_id>', ['1','2'], {<optional config>}), text
Table 3. Example results
score metadata id vector text entity

null

{city: "Berlin", foo: "one"}

null

null

null

null

null

{city: "Berlin", foo: "two"}

null

null

null

null

Get vectors with {allResults: true}
CALL apoc.vectordb.chroma.get($host, '<collection_id>', ['1','2'], {<optional config>}), text
Table 4. Example results
score metadata id vector text entity

null

{city: "Berlin", foo: "one"}

1

[…​]

ajeje

null

null

{city: "Berlin", foo: "two"}

2

[…​]

brazorf

null

Query vectors (it leverages this API)
CALL apoc.vectordb.chroma.queryAndUpdate($host,
    '<collection_id>',
    [0.2, 0.1, 0.9, 0.7],
    {city: 'London'},
    5,
    {allResults: true, <optional config>}), text
Table 5. Example results
score metadata id vector text

1,

{city: "Berlin", foo: "one"}

1

[…​]

ajeje

0.1

{city: "Berlin", foo: "two"}

2

[…​]

brazorf

We can define a mapping, to fetch the associated nodes and relationships and optionally create them, by leveraging the vector metadata.

For example, if we have created 2 vectors with the above upsert procedures, we can populate some existing nodes (i.e. (:Test {myId: 'one'}) and (:Test {myId: 'two'})):

Query vectors
CALL apoc.vectordb.chroma.queryAndUpdate($host, '<collection_id>',
    [0.2, 0.1, 0.9, 0.7],
    {},
    5,
    { mapping: {
            embeddingKey: "vect",
            nodeLabel: "Test",
            entityKey: "myId",
            metadataKey: "foo"
        }
    })

which populates the two nodes as: (:Test {myId: 'one', city: 'Berlin', vect: [vector1]}) and (:Test {myId: 'two', city: 'London', vect: [vector2]}), which will be returned in the entity column result.

We can also set the mapping configuration mode to CREATE_IF_MISSING (which creates nodes if not exist), READ_ONLY (to search for nodes/rels, without making updates) or UPDATE_EXISTING (default behavior):

CALL apoc.vectordb.chroma.queryAndUpdate($host, '<collection_id>',
    [0.2, 0.1, 0.9, 0.7],
    {},
    5,
    { mapping: {
            mode: "CREATE_IF_MISSING",
            embeddingKey: "vect",
            nodeLabel: "Test",
            entityKey: "myId",
            metadataKey: "foo"
        }
    })

which creates and 2 new nodes as above.

Or, we can populate an existing relationship (i.e. (:Start)-[:TEST {myId: 'one'}]→(:End) and (:Start)-[:TEST {myId: 'two'}]→(:End)):

CALL apoc.vectordb.chroma.queryAndUpdate($host, '<collection_id>',
    [0.2, 0.1, 0.9, 0.7],
    {},
    5,
    { mapping: {
            embeddingKey: "vect",
            relType: "TEST",
            entityKey: "myId",
            metadataKey: "foo"
        }
    })

which populates the two relationships as: ()-[:TEST {myId: 'one', city: 'Berlin', vect: [vector1]}]-() and ()-[:TEST {myId: 'two', city: 'London', vect: [vector2]}]-(), which will be returned in the entity column result.

We can also use mapping for apoc.vectordb.chroma.query procedure, to search for nodes/rels fitting label/type and metadataKey, without making updates (i.e. equivalent to *.queryOrUpdate procedure with mapping config having mode: "READ_ONLY").

For example, with the previous relationships, we can execute the following procedure, which just return the relationships in the column rel:

CALL apoc.vectordb.weaviate.query($host, 'test_collection',
    [0.2, 0.1, 0.9, 0.7],
    {},
    5,
    { fields: ["city", "foo"],
      mapping: {
        relType: "TEST",
        entityKey: "myId",
        metadataKey: "foo"
      }
    })

We can use mapping with apoc.vectordb.chroma.get* procedures as well

To optimize performances, we can choose what to YIELD with the apoc.vectordb.chroma.query and the apoc.vectordb.chroma.get procedures. For example, by executing a CALL apoc.vectordb.chroma.query(…​) YIELD metadata, score, id, the RestAPI request will have an {"include": ["metadatas", "documents", "distances"]}, so that we do not return the other values that we do not need.

It is possible to execute vector db procedures together with the apoc.ml.rag as follow:

CALL apoc.vectordb.chroma.getAndUpdate($host, $collection, [<id1>, <id2>], $conf) YIELD node, metadata, id, vector
WITH collect(node) as paths
CALL apoc.ml.rag(paths, $attributes, $question, $confPrompt) YIELD value
RETURN value

which returns a string that answers the $question by leveraging the embeddings of the db vector.

Delete vectors (it leverages this API)
CALL apoc.vectordb.chroma.delete($host, '<collection_id>', [1,2], {<optional config>})

which returns an array of strings of deleted ids. For example, ["1", "2"]