query | R Documentation |
Query Documents in a Collection
query(
client,
collection_name,
query_embeddings,
n_results = 10L,
where = NULL,
where_document = NULL,
include = c("documents", "metadatas", "distances"),
tenant = "default_tenant",
database = "default_database"
)
client |
A ChromaDB client object |
collection_name |
Name of the collection |
query_embeddings |
List of query embeddings (must be a list of numeric vectors) |
n_results |
Number of results to return per query (default: 10) |
where |
Optional filtering conditions |
where_document |
Optional document-based filtering conditions |
include |
Optional vector of what to include in results. Possible values: "documents", "embeddings", "metadatas", "distances", "uris", "data" (default: c("documents", "metadatas", "distances")) |
tenant |
The tenant name (default: "default") |
database |
The database name (default: "default") |
Note that ChromaDB's API only accepts embeddings for queries. If you want to query using text, you need to first convert your text to embeddings using an embedding model (e.g., using OpenAI's API, HuggingFace's API, or a local model).
Example:
# First convert text to embeddings using your preferred method text_embedding <- your_embedding_function("your search text") # Then query using the embedding result <- query(client, "my_collection", query_embeddings = list(text_embedding))
A list containing the query results. Each element (documents, metadatas, distances) is a nested list, so use double brackets [[]] to access individual elements.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.