langchain-chroma¶
注意
此软件包参考尚未完全迁移到 v1。
langchain_chroma ¶
用于 Chroma 向量数据库的 LangChain 集成。
Chroma ¶
Bases: VectorStore
Chroma 向量存储集成。
关键初始化参数 — 索引参数:collection_name:集合的名称。embedding_function:要使用的嵌入函数。
关键初始化参数 — 客户端参数:client:要使用的 Chroma 客户端。client_settings:Chroma 客户端设置。persist_directory:用于持久化集合的目录。host:已部署的 Chroma 服务器的主机名。port:已部署的 Chroma 服务器的连接端口。默认为 8000。ssl:是否与已部署的 Chroma 服务器建立 SSL 连接。默认为 False。headers:要发送到已部署的 Chroma 服务器的 HTTP 标头。chroma_cloud_api_key:Chroma Cloud API 密钥。tenant:租户 ID。Chroma Cloud 连接必需。对于本地 Chroma 服务器,默认为 'default_tenant'。database:数据库名称。Chroma Cloud 连接必需。默认为 'default_database'。
实例化
添加文档
from langchain_core.documents import Document
document_1 = Document(page_content="foo", metadata={"baz": "bar"})
document_2 = Document(page_content="thud", metadata={"bar": "baz"})
document_3 = Document(page_content="i will be deleted :(")
documents = [document_1, document_2, document_3]
ids = ["1", "2", "3"]
vector_store.add_documents(documents=documents, ids=ids)
更新文档
搜索
带筛选的搜索
带分数的搜索
异步
# add documents
# await vector_store.aadd_documents(documents=documents, ids=ids)
# delete documents
# await vector_store.adelete(ids=["3"])
# search
# results = vector_store.asimilarity_search(query="thud",k=1)
# search with score
results = await vector_store.asimilarity_search_with_score(query="qux", k=1)
for doc, score in results:
print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")
用作检索器
| 方法 | 描述 |
|---|---|
aget_by_ids |
通过 ID 异步获取文档。 |
adelete |
按向量 ID 或其他条件异步删除。 |
aadd_texts |
通过嵌入异步运行更多文本并添加到 `VectorStore`。 |
add_documents |
在 `VectorStore` 中添加或更新文档。 |
aadd_documents |
异步运行更多文档通过嵌入并添加到 `VectorStore`。 |
search |
使用指定的搜索类型返回与查询最相似的文档。 |
asearch |
异步返回与查询最相似的文档,使用指定的搜索类型。 |
asimilarity_search_with_score |
异步运行带距离的相似性搜索。 |
similarity_search_with_relevance_scores |
返回文档和在 `[0, 1]` 范围内的相关性分数。 |
asimilarity_search_with_relevance_scores |
异步返回文档和在 `[0, 1]` 范围内的相关性分数。 |
asimilarity_search |
异步返回与查询最相似的文档。 |
asimilarity_search_by_vector |
异步返回与嵌入向量最相似的文档。 |
amax_marginal_relevance_search |
异步返回使用最大边际相关性选择的文档。 |
amax_marginal_relevance_search_by_vector |
异步返回使用最大边际相关性选择的文档。 |
afrom_documents |
异步返回从文档和嵌入初始化的 `VectorStore`。 |
afrom_texts |
异步返回从文本和嵌入初始化的 `VectorStore`。 |
as_retriever |
返回从此 `VectorStore` 初始化的 `VectorStoreRetriever`。 |
__init__ |
使用 Chroma 客户端进行初始化。 |
encode_image |
从图像 URI 获取 base64 字符串。 |
fork |
派生此向量存储。 |
add_images |
通过嵌入处理更多图像并将其添加到 |
add_texts |
通过嵌入运行更多文本并添加到 `VectorStore`。 |
similarity_search |
使用 Chroma 运行相似性搜索。 |
similarity_search_by_vector |
返回与嵌入向量最相似的文档。 |
similarity_search_by_vector_with_relevance_scores |
返回与嵌入向量最相似的文档和相似度分数。 |
similarity_search_with_score |
使用 Chroma 运行带距离的相似性搜索。 |
similarity_search_with_vectors |
使用 Chroma 运行带向量的相似性搜索。 |
similarity_search_by_image |
根据给定的图像 URI 搜索相似的图像。 |
similarity_search_by_image_with_relevance_score |
根据给定的图像 URI 搜索相似的图像。 |
max_marginal_relevance_search_by_vector |
返回使用最大边际相关性选择的文档。 |
max_marginal_relevance_search |
返回使用最大边际相关性选择的文档。 |
delete_collection |
删除集合。 |
reset_collection |
重置集合。 |
get |
获取集合。 |
get_by_ids |
根据 ID 获取文档。 |
update_document |
更新集合中的一个文档。 |
update_documents |
更新集合中的一个文档。 |
from_texts |
从原始文档创建 Chroma 向量存储。 |
from_documents |
从文档列表创建 Chroma 向量存储。 |
delete |
通过向量 ID 删除。 |
aget_by_ids 异步 ¶
adelete 异步 ¶
aadd_texts 异步 ¶
aadd_texts(
texts: Iterable[str],
metadatas: list[dict] | None = None,
*,
ids: list[str] | None = None,
**kwargs: Any,
) -> list[str]
通过嵌入异步运行更多文本并添加到 `VectorStore`。
| 参数 | 描述 |
|---|---|
texts
|
要添加到 `VectorStore` 的字符串的可迭代对象。 |
metadatas
|
与文本关联的元数据可选列表。 |
ids
|
可选列表 |
**kwargs
|
`VectorStore` 特定参数。
类型: |
| 返回 | 描述 |
|---|---|
list[str]
|
将文本添加到 `VectorStore` 后返回的 ID 列表。 |
| 引发 | 描述 |
|---|---|
ValueError
|
如果元数据的数量与文本的数量不匹配。 |
ValueError
|
如果 ID 的数量与文本的数量不匹配。 |
add_documents ¶
aadd_documents 异步 ¶
search ¶
使用指定的搜索类型返回与查询最相似的文档。
| 参数 | 描述 |
|---|---|
query
|
输入文本。
类型: |
search_type
|
要执行的搜索类型。可以是 `'similarity'`、`'mmr'` 或 `'similarity_score_threshold'`。
类型: |
**kwargs
|
传递给搜索方法的参数。
类型: |
| 返回 | 描述 |
|---|---|
list[Document]
|
与查询最相似的 `Document` 对象列表。 |
| 引发 | 描述 |
|---|---|
ValueError
|
如果 `search_type` 不是 `'similarity'`、`'mmr'` 或 `'similarity_score_threshold'` 之一。 |
asearch 异步 ¶
异步返回与查询最相似的文档,使用指定的搜索类型。
| 参数 | 描述 |
|---|---|
query
|
输入文本。
类型: |
search_type
|
要执行的搜索类型。可以是 `'similarity'`、`'mmr'` 或 `'similarity_score_threshold'`。
类型: |
**kwargs
|
传递给搜索方法的参数。
类型: |
| 返回 | 描述 |
|---|---|
list[Document]
|
与查询最相似的 `Document` 对象列表。 |
| 引发 | 描述 |
|---|---|
ValueError
|
如果 `search_type` 不是 `'similarity'`、`'mmr'` 或 `'similarity_score_threshold'` 之一。 |
asimilarity_search_with_score 异步 ¶
similarity_search_with_relevance_scores ¶
asimilarity_search_with_relevance_scores 异步 ¶
asimilarity_search 异步 ¶
asimilarity_search_by_vector 异步 ¶
amax_marginal_relevance_search 异步 ¶
amax_marginal_relevance_search(
query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any
) -> list[Document]
异步返回使用最大边际相关性选择的文档。
最大边际相关性优化查询相似度与所选文档之间的多样性。
| 参数 | 描述 |
|---|---|
query
|
用于查找相似文档的文本。
类型: |
k
|
要返回的 `Document` 对象数量。
TYPE: |
fetch_k
|
要获取并传递给 MMR 算法的 `Document` 对象数量。
类型: |
lambda_mult
|
一个介于 `0` 和 `1` 之间的数字,决定了结果之间的多样性程度,其中 `0` 对应最大多样性,`1` 对应最小多样性。
类型: |
**kwargs
|
传递给搜索方法的参数。
类型: |
| 返回 | 描述 |
|---|---|
list[Document]
|
通过最大边际相关性选择的 `Document` 对象列表。 |
amax_marginal_relevance_search_by_vector 异步 ¶
amax_marginal_relevance_search_by_vector(
embedding: list[float],
k: int = 4,
fetch_k: int = 20,
lambda_mult: float = 0.5,
**kwargs: Any,
) -> list[Document]
异步返回使用最大边际相关性选择的文档。
最大边际相关性优化查询相似度与所选文档之间的多样性。
| 参数 | 描述 |
|---|---|
embedding
|
用于查找相似文档的嵌入。 |
k
|
要返回的 `Document` 对象数量。
TYPE: |
fetch_k
|
要获取并传递给 MMR 算法的 `Document` 对象数量。
类型: |
lambda_mult
|
一个介于 `0` 和 `1` 之间的数字,决定了结果之间的多样性程度,其中 `0` 对应最大多样性,`1` 对应最小多样性。
类型: |
**kwargs
|
传递给搜索方法的参数。
类型: |
| 返回 | 描述 |
|---|---|
list[Document]
|
通过最大边际相关性选择的 `Document` 对象列表。 |
afrom_documents 异步 类方法 ¶
afrom_documents(
documents: list[Document], embedding: Embeddings, **kwargs: Any
) -> Self
异步返回从文档和嵌入初始化的 `VectorStore`。
| 参数 | 描述 |
|---|---|
documents
|
要添加到 `VectorStore` 的 `Document` 对象列表。 |
embedding
|
要使用的嵌入函数。
TYPE: |
**kwargs
|
附加的关键字参数。
类型: |
| 返回 | 描述 |
|---|---|
Self
|
从文档和嵌入初始化的 `VectorStore`。 |
afrom_texts 异步 类方法 ¶
as_retriever ¶
as_retriever(**kwargs: Any) -> VectorStoreRetriever
返回从此 `VectorStore` 初始化的 `VectorStoreRetriever`。
| 参数 | 描述 |
|---|---|
**kwargs
|
传递给搜索函数的关键字参数。可以包括
类型: |
| 返回 | 描述 |
|---|---|
VectorStoreRetriever
|
`VectorStore` 的检索器类。 |
示例
# Retrieve more documents with higher diversity
# Useful if your dataset has many similar documents
docsearch.as_retriever(
search_type="mmr", search_kwargs={"k": 6, "lambda_mult": 0.25}
)
# Fetch more documents for the MMR algorithm to consider
# But only return the top 5
docsearch.as_retriever(search_type="mmr", search_kwargs={"k": 5, "fetch_k": 50})
# Only retrieve documents that have a relevance score
# Above a certain threshold
docsearch.as_retriever(
search_type="similarity_score_threshold",
search_kwargs={"score_threshold": 0.8},
)
# Only get the single most similar document from the dataset
docsearch.as_retriever(search_kwargs={"k": 1})
# Use a filter to only retrieve documents from a specific paper
docsearch.as_retriever(
search_kwargs={"filter": {"paper_title": "GPT-4 Technical Report"}}
)
__init__ ¶
__init__(
collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME,
embedding_function: Embeddings | None = None,
persist_directory: str | None = None,
host: str | None = None,
port: int | None = None,
headers: dict[str, str] | None = None,
chroma_cloud_api_key: str | None = None,
tenant: str | None = None,
database: str | None = None,
client_settings: Settings | None = None,
collection_metadata: dict | None = None,
collection_configuration: CreateCollectionConfiguration | None = None,
client: ClientAPI | None = None,
relevance_score_fn: Callable[[float], float] | None = None,
create_collection_if_not_exists: bool | None = True,
*,
ssl: bool = False,
) -> None
使用 Chroma 客户端进行初始化。
| 参数 | 描述 |
|---|---|
collection_name
|
要创建的集合的名称。
类型: |
embedding_function
|
嵌入类对象。用于嵌入文本。
TYPE: |
persist_directory
|
用于持久化集合的目录。
类型: |
host
|
已部署的 Chroma 服务器的主机名。
类型: |
port
|
已部署的 Chroma 服务器的连接端口。默认为 8000。
TYPE: |
ssl
|
是否与已部署的 Chroma 服务器建立 SSL 连接。默认为 False。
类型: |
headers
|
要发送到已部署的 Chroma 服务器的 HTTP 标头。 |
chroma_cloud_api_key
|
Chroma Cloud API 密钥。
类型: |
tenant
|
租户 ID。Chroma Cloud 连接必需。对于本地 Chroma 服务器,默认为 'default_tenant'。
类型: |
database
|
数据库名称。Chroma Cloud 连接必需。默认为 'default_database'。
类型: |
client_settings
|
Chroma 客户端设置
类型: |
collection_metadata
|
集合配置。
类型: |
collection_configuration
|
集合的索引配置。
类型: |
client
|
Chroma 客户端。文档:https://docs.trychroma.com/reference/python/client
类型: |
relevance_score_fn
|
用于从距离计算相关性分数的函数。仅在 |
create_collection_if_not_exists
|
如果集合不存在,是否创建它。默认为
类型: |
__query_collection ¶
__query_collection(
query_texts: list[str] | None = None,
query_embeddings: list[list[float]] | None = None,
n_results: int = 4,
where: dict[str, str] | None = None,
where_document: dict[str, str] | None = None,
**kwargs: Any,
) -> list[Document] | QueryResult
查询 chroma 集合。
| 参数 | 描述 |
|---|---|
query_texts
|
查询文本列表。 |
query_embeddings
|
查询嵌入列表。 |
n_results
|
要返回的结果数。
TYPE: |
where
|
用于按元数据过滤结果的字典。例如 {"color" : "red"}。 |
where_document
|
用于按文档内容过滤的字典。例如 {"$contains": "hello"}。 |
kwargs
|
传递给 Chroma 集合查询的其他关键字参数。
类型: |
| 返回 | 描述 |
|---|---|
list[Document] | QueryResult
|
为提供的 |
list[Document] | QueryResult
|
query_embeddings 或 query_texts 返回的 |
查看更多:https://docs.trychroma.com/reference/py-collection#query
fork ¶
add_images ¶
add_texts ¶
add_texts(
texts: Iterable[str],
metadatas: list[dict] | None = None,
ids: list[str] | None = None,
**kwargs: Any,
) -> list[str]
通过嵌入运行更多文本并添加到 `VectorStore`。
| 参数 | 描述 |
|---|---|
texts
|
要添加到 `VectorStore` 的文本。 |
metadatas
|
可选的元数据列表。查询时,可以根据此元数据进行筛选。 |
ids
|
可选的 ID 列表。(没有 ID 的项目将被分配 UUID) |
kwargs
|
附加的关键字参数。
类型: |
| 返回 | 描述 |
|---|---|
list[str]
|
已添加文本的 ID 列表。 |
| 引发 | 描述 |
|---|---|
ValueError
|
当元数据不正确时。 |
similarity_search ¶
similarity_search_by_vector ¶
similarity_search_by_vector(
embedding: list[float],
k: int = DEFAULT_K,
filter: dict[str, str] | None = None,
where_document: dict[str, str] | None = None,
**kwargs: Any,
) -> list[Document]
similarity_search_by_vector_with_relevance_scores ¶
similarity_search_by_vector_with_relevance_scores(
embedding: list[float],
k: int = DEFAULT_K,
filter: dict[str, str] | None = None,
where_document: dict[str, str] | None = None,
**kwargs: Any,
) -> list[tuple[Document, float]]
返回与嵌入向量最相似的文档和相似度分数。
| 参数 | 描述 |
|---|---|
embedding
|
用于查找相似文档的嵌入。
类型: |
k
|
要返回的文档数量。
类型: |
filter
|
按元数据筛选。 |
where_document
|
用于按文档筛选的字典。例如 {"$contains": "hello"}。 |
kwargs
|
传递给 Chroma 集合查询的其他关键字参数。
类型: |
| 返回 | 描述 |
|---|---|
list[tuple[Document, float]]
|
与查询文本最相似的文档列表以及每个文档的相关性分数 |
list[tuple[Document, float]]
|
(浮点数)。分数越低表示相似度越高。 |
similarity_search_with_score ¶
similarity_search_with_score(
query: str,
k: int = DEFAULT_K,
filter: dict[str, str] | None = None,
where_document: dict[str, str] | None = None,
**kwargs: Any,
) -> list[tuple[Document, float]]
使用 Chroma 运行带距离的相似性搜索。
| 参数 | 描述 |
|---|---|
query
|
要搜索的查询文本。
类型: |
k
|
要返回的结果数。
类型: |
filter
|
按元数据筛选。 |
where_document
|
用于按文档内容筛选的字典。例如 {"$contains": "hello"}。 |
kwargs
|
传递给 Chroma 集合查询的其他关键字参数。
类型: |
| 返回 | 描述 |
|---|---|
list[tuple[Document, float]]
|
与查询文本最相似的文档列表以及 |
list[tuple[Document, float]]
|
每个文档的距离(浮点数)。分数越低表示相似度越高。 |
similarity_search_with_vectors ¶
similarity_search_with_vectors(
query: str,
k: int = DEFAULT_K,
filter: dict[str, str] | None = None,
where_document: dict[str, str] | None = None,
**kwargs: Any,
) -> list[tuple[Document, ndarray]]
similarity_search_by_image ¶
similarity_search_by_image(
uri: str, k: int = DEFAULT_K, filter: dict[str, str] | None = None, **kwargs: Any
) -> list[Document]
similarity_search_by_image_with_relevance_score ¶
similarity_search_by_image_with_relevance_score(
uri: str, k: int = DEFAULT_K, filter: dict[str, str] | None = None, **kwargs: Any
) -> list[tuple[Document, float]]
根据给定的图像 URI 搜索相似的图像。
| 参数 | 描述 |
|---|---|
uri
|
要搜索的图像的 URI。
类型: |
k
|
要返回的结果数。
类型: |
filter
|
按元数据筛选。 |
**kwargs
|
要传递给函数的其他参数。
类型: |
| 返回 | 描述 |
|---|---|
list[tuple[Document, float]]
|
包含与查询图像相似的文档及其 |
list[tuple[Document, float]]
|
相似度分数的元组列表。每个元组中的第 0 个元素是一个 LangChain 文档对象。 |
list[tuple[Document, float]]
|
页面内容是 b64 编码的图像,元数据是默认的或由用户定义的。 |
| 引发 | 描述 |
|---|---|
ValueError
|
如果嵌入函数不支持图像嵌入。 |
max_marginal_relevance_search_by_vector ¶
max_marginal_relevance_search_by_vector(
embedding: list[float],
k: int = DEFAULT_K,
fetch_k: int = 20,
lambda_mult: float = 0.5,
filter: dict[str, str] | None = None,
where_document: dict[str, str] | None = None,
**kwargs: Any,
) -> list[Document]
返回使用最大边际相关性选择的文档。
最大边际相关性优化查询相似度与所选文档之间的多样性。
| 参数 | 描述 |
|---|---|
embedding
|
用于查找相似文档的嵌入。 |
k
|
要返回的 `Document` 对象数量。
类型: |
fetch_k
|
要获取并传递给 MMR 算法的 `Document` 对象数量。
类型: |
lambda_mult
|
介于 0 和 1 之间的数字,用于确定结果之间的多样性程度,其中
类型: |
filter
|
按元数据筛选。 |
where_document
|
用于按文档内容筛选的字典。例如 |
kwargs
|
传递给 Chroma 集合查询的其他关键字参数。
类型: |
| 返回 | 描述 |
|---|---|
list[Document]
|
通过最大边际相关性选择的 `Document` 对象列表。 |
max_marginal_relevance_search ¶
max_marginal_relevance_search(
query: str,
k: int = DEFAULT_K,
fetch_k: int = 20,
lambda_mult: float = 0.5,
filter: dict[str, str] | None = None,
where_document: dict[str, str] | None = None,
**kwargs: Any,
) -> list[Document]
返回使用最大边际相关性选择的文档。
最大边际相关性优化查询相似度与所选文档之间的多样性。
| 参数 | 描述 |
|---|---|
query
|
用于查找相似文档的文本。
类型: |
k
|
要返回的文档数量。
类型: |
fetch_k
|
要获取以传递给 MMR 算法的文档数量。
类型: |
lambda_mult
|
一个介于 `0` 和 `1` 之间的数字,决定了结果之间的多样性程度,其中 `0` 对应最大多样性,`1` 对应最小多样性。
类型: |
filter
|
按元数据筛选。 |
where_document
|
用于按文档内容筛选的字典。例如 |
kwargs
|
传递给 Chroma 集合查询的其他关键字参数。
类型: |
| 返回 | 描述 |
|---|---|
list[Document]
|
通过最大边际相关性选择的 `Document` 对象列表。 |
| 引发 | 描述 |
|---|---|
ValueError
|
如果未提供嵌入函数。 |
get ¶
get(
ids: str | list[str] | None = None,
where: Where | None = None,
limit: int | None = None,
offset: int | None = None,
where_document: WhereDocument | None = None,
include: list[str] | None = None,
) -> dict[str, Any]
获取集合。
| 参数 | 描述 |
|---|---|
ids
|
要获取的嵌入的 ID。可选。 |
where
|
一个 Where 类型的字典,用于筛选结果。例如
类型: |
limit
|
要返回的文档数量。可选。
TYPE: |
offset
|
开始返回结果的偏移量。用于分页结果时与 limit 一起使用。可选。
TYPE: |
where_document
|
一个 WhereDocument 类型的字典,用于按文档筛选。例如
类型: |
包含
|
一个列表,指定结果中要包含的内容。可以包含 |
| 返回 | 描述 |
|---|---|
dict[str, Any]
|
一个包含键 |
get_by_ids ¶
update_document ¶
update_documents ¶
from_texts 类方法 ¶
from_texts(
texts: list[str],
embedding: Embeddings | None = None,
metadatas: list[dict] | None = None,
ids: list[str] | None = None,
collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME,
persist_directory: str | None = None,
host: str | None = None,
port: int | None = None,
headers: dict[str, str] | None = None,
chroma_cloud_api_key: str | None = None,
tenant: str | None = None,
database: str | None = None,
client_settings: Settings | None = None,
client: ClientAPI | None = None,
collection_metadata: dict | None = None,
collection_configuration: CreateCollectionConfiguration | None = None,
*,
ssl: bool = False,
**kwargs: Any,
) -> Chroma
从原始文档创建 Chroma 向量存储。
如果指定了 persist_directory,集合将持久化到该目录。否则,数据将是临时的内存数据。
| 参数 | 描述 |
|---|---|
texts
|
要添加到集合中的文本列表。 |
collection_name
|
要创建的集合的名称。
类型: |
persist_directory
|
用于持久化集合的目录。
类型: |
host
|
已部署的 Chroma 服务器的主机名。
类型: |
port
|
已部署的 Chroma 服务器的连接端口。默认为 8000。
TYPE: |
ssl
|
是否与已部署的 Chroma 服务器建立 SSL 连接。默认为 False。
类型: |
headers
|
要发送到已部署的 Chroma 服务器的 HTTP 标头。 |
chroma_cloud_api_key
|
Chroma Cloud API 密钥。
类型: |
tenant
|
租户 ID。Chroma Cloud 连接必需。对于本地 Chroma 服务器,默认为 'default_tenant'。
类型: |
database
|
数据库名称。Chroma Cloud 连接必需。默认为 'default_database'。
类型: |
embedding
|
嵌入函数。
TYPE: |
metadatas
|
元数据列表。 |
ids
|
文档 ID 列表。 |
client_settings
|
Chroma 客户端设置。
类型: |
client
|
Chroma 客户端。文档:https://docs.trychroma.com/reference/python/client
类型: |
collection_metadata
|
集合配置。
类型: |
collection_configuration
|
集合的索引配置。
类型: |
kwargs
|
用于初始化 Chroma 客户端的其他关键字参数。
类型: |
| 返回 | 描述 |
|---|---|
Chroma
|
Chroma 向量存储。
类型: |
from_documents 类方法 ¶
from_documents(
documents: list[Document],
embedding: Embeddings | None = None,
ids: list[str] | None = None,
collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME,
persist_directory: str | None = None,
host: str | None = None,
port: int | None = None,
headers: dict[str, str] | None = None,
chroma_cloud_api_key: str | None = None,
tenant: str | None = None,
database: str | None = None,
client_settings: Settings | None = None,
client: ClientAPI | None = None,
collection_metadata: dict | None = None,
collection_configuration: CreateCollectionConfiguration | None = None,
*,
ssl: bool = False,
**kwargs: Any,
) -> Chroma
从文档列表创建 Chroma 向量存储。
如果指定了 persist_directory,集合将持久化到该目录。否则,数据将是临时的内存数据。
| 参数 | 描述 |
|---|---|
collection_name
|
要创建的集合的名称。
类型: |
persist_directory
|
用于持久化集合的目录。
类型: |
host
|
已部署的 Chroma 服务器的主机名。
类型: |
port
|
已部署的 Chroma 服务器的连接端口。默认为 8000。
TYPE: |
ssl
|
是否与已部署的 Chroma 服务器建立 SSL 连接。
类型: |
headers
|
要发送到已部署的 Chroma 服务器的 HTTP 标头。 |
chroma_cloud_api_key
|
Chroma Cloud API 密钥。
类型: |
tenant
|
租户 ID。Chroma Cloud 连接必需。对于本地 Chroma 服务器,默认为 'default_tenant'。
类型: |
database
|
数据库名称。Chroma Cloud 连接必需。默认为 'default_database'。
类型: |
ids
|
文档 ID 列表。 |
documents
|
要添加到 |
embedding
|
嵌入函数。
TYPE: |
client_settings
|
Chroma 客户端设置。
类型: |
client
|
Chroma 客户端。文档:https://docs.trychroma.com/reference/python/client
类型: |
collection_metadata
|
集合配置。
类型: |
collection_configuration
|
集合的索引配置。
类型: |
kwargs
|
用于初始化 Chroma 客户端的其他关键字参数。
类型: |
| 返回 | 描述 |
|---|---|
Chroma
|
Chroma 向量存储。
类型: |