集合定义
一个集合定义指定了如何在 Weaviate 中存储和索引一组数据对象。本页讨论了配置集合的可用参数。
集合定义参数
这些是在创建集合时可以设置的顶级参数。
| 参数 | 类型 | 描述 | 默认值 | 可变 |
|---|---|---|---|---|
类 | 字符串 | 集合的名称。 | (必需) | 否 |
描述 | 字符串 | 集合的描述。 | "" | 是 |
属性 | 数组 | 一个属性对象数组,定义数据模式。 | [] | 部分* |
invertedIndexConfig | 对象 | 倒排索引的配置,影响过滤和关键字搜索。 | 请参阅倒排索引参考 | 是 |
vectorConfig | 对象 | 配置多个命名的向量,每个向量都有自己的vectorizer、vectorIndexType和vectorIndexConfig字段。 | null | 部分** |
vectorizer | 字符串 | 要使用的向量化模块。 | 默认向量化器由环境变量定义。有关模块特定配置默认值,请参阅模型提供程序 | 否 |
vectorIndexType | 字符串 | 要使用的向量索引类型(hnsw、flat、dynamic)。 | hnsw | 否 |
moduleConfig | 对象 | 模块特定的配置设置。 | 请参阅模块配置 | 部分 |
vectorIndexConfig | 对象 | 特定于所选vectorIndexType的配置设置。 | 请参阅向量索引参考 | 部分 |
shardingConfig | 对象 | 控制多节点集群中的分片行为。 | 请参阅分片部分 | 否 |
replicationConfig | 对象 | 控制容错的数据复制设置。 | 请参阅复制部分 | 部分 |
multiTenancyConfig | 对象 | 配置以启用集合的多租户。 | 请参阅多租户部分 | 部分 |
* 可以添加新属性;现有属性无法修改
** 可以添加新的命名向量;某些向量索引设置是可变的
示例集合配置 - JSON 对象
包含属性的完整集合对象的示例
{
"class": "Article", // The name of the collection in string format
"description": "An article", // A description for your reference
"vectorIndexType": "hnsw", // Defaults to hnsw
"vectorIndexConfig": {
... // Vector index type specific settings, including distance metric
},
"vectorizer": "text2vec-contextionary", // Vectorizer to use for data objects added to this collection
"moduleConfig": {
"text2vec-contextionary": {
"vectorizeClassName": true // Include the collection name in vector calculation (default true)
}
},
"properties": [ // An array of the properties you are adding, same as a Property Object
{
"name": "title", // The name of the property
"description": "title of the article", // A description for your reference
"dataType": [ // The data type of the object as described above. When
// creating cross-references, a property can have
// multiple data types, hence the array syntax.
"text"
],
"moduleConfig": { // Module-specific settings
"text2vec-contextionary": {
"skip": true, // If true, the whole property will NOT be included in
// vectorization. Default is false, meaning that the
// object will be NOT be skipped.
"vectorizePropertyName": true, // Whether the name of the property is used in the
// calculation for the vector position of data
// objects. Default false.
}
},
"indexFilterable": true, // Optional, default is true. By default each property
// is indexed with a roaring bitmap index where
// available for efficient filtering.
"indexSearchable": true // Optional, default is true. By default each property
// is indexed with a searchable index for
// BM25-suitable Map index for BM25 or hybrid
// searching.
}
],
"invertedIndexConfig": { // Optional, index configuration
"stopwords": {
... // Optional, controls which words should be ignored in the inverted index, see section below
},
"indexTimestamps": false, // Optional, maintains inverted indexes for each object by its internal timestamps
"indexNullState": false, // Optional, maintains inverted indexes for each property regarding its null state
"indexPropertyLength": false // Optional, maintains inverted indexes for each property by its length
},
"shardingConfig": {
... // Optional, controls behavior of the collection in a
// multi-node setting, see section below
},
"multiTenancyConfig": {"enabled": true} // Optional, for enabling multi-tenancy for this
// collection (default: false)
}
代码示例 - 如何创建集合
此代码示例演示了如何通过客户端库配置集合参数
如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue。
from weaviate.classes.config import (
Configure,
DataType,
Property,
ReplicationDeletionStrategy,
VectorDistances,
VectorFilterStrategy,
)
client.collections.create(
"Article",
description="A collection of articles",
properties=[
Property(name="title", data_type=DataType.TEXT),
Property(name="body", data_type=DataType.TEXT),
],
vector_config=Configure.Vectors.text2vec_openai(
name="default",
source_properties=["title", "body"],
vector_index_config=Configure.VectorIndex.hnsw(
ef_construction=300,
distance_metric=VectorDistances.COSINE,
filter_strategy=VectorFilterStrategy.SWEEPING,
),
),
multi_tenancy_config=Configure.multi_tenancy(False),
sharding_config=Configure.sharding(
virtual_per_physical=128,
desired_count=1,
desired_virtual_count=128,
),
replication_config=Configure.replication(
factor=1,
async_enabled=False,
deletion_strategy=ReplicationDeletionStrategy.TIME_BASED_RESOLUTION,
),
)
有关更多代码示例和配置指南,请访问操作指南:管理集合部分。
class
class是集合的名称。
集合名称以大写字母开头。大写字母用于区分集合名称和当名称用作属性值时的原始数据类型。
考虑以下使用dataType属性的示例
dataType: ["text"]是一个text数据类型。dataType: ["Text"]是对名为Text的集合的交叉引用类型。
首字母之后,集合名称可以使用任何 GraphQL 兼容字符。
集合名称验证正则表达式为/^[A-Z][_0-9A-Za-z]*$/。
Weaviate 遵循 GraphQL 命名约定。
- 集合名称以大写字母开头。
- 属性名称以小写字母开头。
如果使用大写字母开头来定义属性名称,Weaviate 会在内部将其更改为小写字母。
description
集合的描述。这仅供参考,也可为Weaviate Agents提供更多信息。
属性
| 参数 | 类型 | 描述 | 默认值 | 可变 |
|---|---|---|---|---|
名称 | 字符串 | 属性的名称。 | (必需) | 否 |
dataType | 数组 | 包含一个或多个数据类型的数组。对于交叉引用,使用大写的集合名称(例如,["Article"])。 | (必需) | 否 |
描述 | 字符串 | 属性的描述,仅供参考。 | null | 是 |
tokenization | 字符串 | 对于text属性,指定文本如何拆分为用于倒排索引的标记。 | word | 否 |
indexInverted | 布尔值 | 如果为true,则为该属性启用倒排索引。 | true | 否 |
indexFilterable | 布尔值 | 如果为true,则为该属性构建 roaring bitmap 索引,以实现高效的过滤。 | true | 否 |
indexSearchable | 布尔值 | 如果为true,则为该属性构建可搜索的映射索引,适用于 BM25 或混合搜索。 | true | 否 |
indexRangeFilters | 布尔值 | 如果为true,则为数值范围过滤构建 roaring bitmap 索引。 | false | 否 |
invertedIndexConfig | 对象 | 针对倒排索引设置的属性级别覆盖,例如bm25参数。 | {} | 否 |
moduleConfig | 对象 | 模块特定的设置,例如跳过此属性的向量化。 | {} | 否 |
示例属性配置 - JSON 对象
包含属性的完整属性对象示例
{
"name": "title", // The name of the property
"description": "title of the article", // A description for your reference
"dataType": [
// The data type of the object as described above. When creating cross-references, a property can have multiple dataTypes.
"text"
],
"tokenization": "word", // Split field contents into word-tokens when indexing into the inverted index. See "Property Tokenization" below for more detail.
"moduleConfig": {
// Module-specific settings
"text2vec-contextionary": {
"skip": true, // If true, the whole property is NOT included in vectorization. Default is false, meaning that the object will be NOT be skipped.
"vectorizePropertyName": true // Whether the name of the property is used in the calculation for the vector position of data objects. Default false.
}
},
"indexFilterable": true, // Optional, default is true. By default each property is indexed with a roaring bitmap index where available for efficient filtering.
"indexSearchable": true // Optional, default is true. By default each property is indexed with a searchable index for BM25-suitable Map index for BM25 or hybrid searching.
}
代码示例 - 如何配置集合属性
此代码示例演示了如何通过客户端库配置属性参数
如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue。
from weaviate.classes.config import Property, DataType
# Note that you can use `client.collections.create_from_dict()` to create a collection from a v3-client-style JSON object
client.collections.create(
"Article",
vector_config=Configure.Vectors.text2vec_openai(),
properties=[ # properties configuration is optional
Property(name="title", data_type=DataType.TEXT),
Property(name="description", data_type=DataType.TEXT, skip_vectorization=True),
Property(name="rating", data_type=DataType.NUMBER),
],
)
有关更多代码示例和配置指南,请访问操作指南:管理集合部分。
name
属性名称可以包含以下字符:/[_A-Za-z][_0-9A-Za-z]*/。
保留字
以下单词是保留的,不能用作属性名称
_additionalid_id
此外,我们强烈建议不要将以下单词用作属性名称,因为未来可能会出现冲突的保留字
vector_vector
tokenization
您可以自定义如何对text数据进行标记化并在倒排索引中进行索引。标记化会影响由bm25和hybrid运算符以及where过滤器返回的结果。
标记化是text属性的属性级别配置。请参阅如何使用客户端库设置标记化选项
示例属性配置 - JSON 对象
{
"classes": [
{
"class": "Question",
"properties": [
{
"dataType": ["text"],
"name": "question",
"tokenization": "word"
},
],
...
"vectorizer": "text2vec-openai"
}
]
}
标准标记化方法
word标记化
描述:通过任何非字母数字字符拆分文本,然后将每个标记小写。这是默认设置。
行为示例:
| 文本 | 标记 |
|---|---|
"Why, hello there!" | ["why", "hello", "there"] |
"Lois & Clark: The New Adventures of Superman" | ["lois", "clark", "the", "new", "adventures", "of", "superman"] |
"variable_name" | ["variable", "name"] |
"Email: john.doe@example.com" | ["email", "john", "doe", "example", "com"] |
何时使用:
- 推荐用于大多数常规文本数据(文章、描述)。
- 当需要不区分大小写和忽略标点符号以进行更宽容的搜索时。
lowercase标记化
描述:仅通过空格拆分文本,然后将每个标记小写。它保留了word标记化会删除的符号。
行为示例:
| 文本 | 标记 |
|---|---|
"Why, hello there!" | ["why,", "hello", "there!"] |
"Lois & Clark: The New Adventures of Superman" | ["lois", "&", "clark:", "the", "new", "adventures", "of", "superman"] |
"variable_name" | ["variable_name"] |
"Email: john.doe@example.com" | ["email:", "john.doe@example.com"] |
何时使用:
- 用于技术数据,其中诸如
&、@或_之类的符号具有意义(例如,代码片段、电子邮件地址)。 - 当需要不区分大小写匹配但必须保留符号时。
whitespace标记化
描述:仅通过空格拆分文本,保留大小写和符号。
行为示例:
| 文本 | 标记 |
|---|---|
"Why, hello there!" | ["Why,", "hello", "there!"] |
"Lois & Clark: The New Adventures of Superman" | ["Lois", "&", "Clark:", "The", "New", "Adventures", "of", "Superman"] |
"variable_name" | ["variable_name"] |
"Email: john.doe@example.com" | ["Email:", "john.doe@example.com"] |
何时使用:
- 当大小写很重要时(例如,专有名词、缩写词或特定代码)。
- 需要仔细构建查询以匹配大小写。
field 分词
描述:将属性的整个值视为单个 token。不进行拆分。
行为示例:
| 文本 | 标记 |
|---|---|
"Why, hello there!" | ["Why, hello there!"] |
"variable_name" | ["variable_name"] |
"Email: john.doe@example.com" | ["Email: john.doe@example.com"] |
何时使用:
- 当您需要完全匹配字段值时。
- 适用于包含唯一标识符(如 URL、UUID 或电子邮件地址)的属性。
- 对关键字搜索用处有限,但对精确过滤功能强大。
特定于语言的分词
标准的tokenization方法对英语和其他使用空格分隔单词的语言效果很好。对于像中文、日语和韩语这样不依赖空格的语言,Weaviate 提供了专门的tokenization方法。
gse 和 trigram tokenization 方法
1.24 中添加对于日语和中文文本,我们建议使用 gse 或 trigram tokenization 方法。由于这些语言不能轻易地使用空格进行分词,因此这些方法比其他方法更有效。
gse tokenizer 默认情况下未加载,以节省资源。要使用它,请在 Weaviate 实例上将环境变量 ENABLE_TOKENIZER_GSE 设置为 true。
gse 分词示例
"素早い茶色の狐が怠けた犬を飛び越えた":["素早", "素早い", "早い", "茶色", "の", "狐", "が", "怠け", "けた", "犬", "を", "飛び", "飛び越え", "越え", "た", "素早い茶色の狐が怠けた犬を飛び越えた"]"すばやいちゃいろのきつねがなまけたいぬをとびこえた":["すばや", "すばやい", "やい", "いち", "ちゃ", "ちゃい", "ちゃいろ", "いろ", "のき", "きつ", "きつね", "つね", "ねが", "がな", "なま", "なまけ", "まけ", "けた", "けたい", "たい", "いぬ", "を", "とび", "とびこえ", "こえ", "た", "すばやいちゃいろのきつねがなまけたいぬをとびこえた"]
trigram 用于模糊匹配虽然最初是为亚洲语言设计的,但 trigram tokenization 对于其他语言的模糊匹配和容错性也同样有效。
kagome_ja tokenization 方法
从 v1.28.0 开始可用。这是一个实验性功能。谨慎使用。
对于日语文本,也可以使用 kagome_ja tokenization 方法。它使用 Kagome tokenizer 和日语 MeCab IPA 词典来拆分属性文本。
kagome_ja tokenizer 默认情况下未加载,以节省资源。要使用它,请在 Weaviate 实例上将环境变量 ENABLE_TOKENIZER_KAGOME_JA 设置为 true。
kagome_ja 分词示例
"春の夜の夢はうつつよりもかなしき 夏の夜の夢はうつつに似たり 秋の夜の夢はうつつを超え 冬の夜の夢は心に響く 山のあなたに小さな村が見える 川の音が静かに耳に届く 風が木々を通り抜ける音 星空の下、すべてが平和である":- [
"春", "の", "夜", "の", "夢", "は", "うつつ", "より", "も", "かなしき", "\n\t", "夏", "の", "夜", "の", "夢", "は", "うつつ", "に", "似", "たり", "\n\t", "秋", "の", "夜", "の", "夢", "は", "うつつ", "を", "超え", "\n\t", "冬", "の", "夜", "の", "夢", "は", "心", "に", "響く", "\n\n\t", "山", "の", "あなた", "に", "小さな", "村", "が", "見える", "\n\t", "川", "の", "音", "が", "静か", "に", "耳", "に", "届く", "\n\t", "風", "が", "木々", "を", "通り抜ける", "音", "\n\t", "星空", "の", "下", "、", "すべて", "が", "平和", "で", "ある"]
- [
"素早い茶色の狐が怠けた犬を飛び越えた":["素早い", "茶色", "の", "狐", "が", "怠け", "た", "犬", "を", "飛び越え", "た"]
"すばやいちゃいろのきつねがなまけたいぬをとびこえた":["すばやい", "ちゃ", "いろ", "の", "きつね", "が", "なまけ", "た", "いぬ", "を", "とびこえ", "た"]
kagome_kr tokenization 方法
从 v1.25.7 开始可用。这是一个实验性功能。谨慎使用。
对于韩语文本,我们建议使用 kagome_kr tokenization 方法。它使用 Kagome tokenizer 和韩语 MeCab (mecab-ko-dic) 词典来拆分属性文本。
kagome_kr tokenizer 默认情况下未加载,以节省资源。要使用它,请在 Weaviate 实例上将环境变量 ENABLE_TOKENIZER_KAGOME_KR 设置为 true。
kagome_kr 分词示例
"아버지가방에들어가신다":["아버지", "가", "방", "에", "들어가", "신다"]
"아버지가 방에 들어가신다":["아버지", "가", "방", "에", "들어가", "신다"]
"결정하겠다":["결정", "하", "겠", "다"]
限制 gse 和 Kagome tokenizers 的数量
gse 和 Kagome tokenizers 可能会占用大量资源并影响 Weaviate 的性能。您可以使用 TOKENIZER_CONCURRENCY_COUNT 环境变量 限制同时运行的 gse 和 Kagome tokenizers 的组合数量。
使用 trigram tokenization 进行模糊匹配
trigram tokenization 方法通过将文本分解为重叠的 3 个字符序列来提供模糊匹配功能。这使得 BM25 搜索即使在存在拼写错误或变体的情况下也能找到匹配项。
trigram 模糊匹配用例
- 容错性:尽管存在拼写错误(例如,“Reliace”匹配“Reliance”),也能找到匹配项
- 名称协调:匹配跨数据集的实体名称变体
- 输入时搜索:构建自动完成功能
- 部分匹配:查找具有部分字符串匹配的对象
工作原理
当文本使用 trigram 进行分词时,它被分解为所有可能的 3 个字符序列
"hello"→["hel", "ell", "llo"]"world"→["wor", "orl", "rld"]
相似的字符串共享许多 trigram,从而实现模糊匹配
"Morgan Stanley"和"Stanley Morgn"共享 trigram,如"sta", "tan", "anl", "nle", "ley"
性能注意事项
- 过滤行为将发生显著变化,因为文本过滤将基于 trigram 分词文本进行,而不是整个单词。
- 由于 token 数量更多,会创建更大的倒排索引。
- 对于大型数据集,可能会影响查询性能。
有选择地在需要模糊匹配的字段上使用 trigram 分词。对于精确匹配,请使用 word 或 field 分词。
决策指南
使用此表快速确定数据的正确分词方法。
| 如果您的数据是... | 考虑 | 因为 |
|---|---|---|
| 通用文本(文章、描述) | word | 不区分大小写,忽略标点符号,宽容 |
代码、带有 _ 或 - 的技术 ID | lowercase | 保留符号,不区分大小写 |
| 名称、大小写重要的缩写 | whitespace | 区分大小写,保留符号 |
| 电子邮件地址、URL、唯一 ID | field | 需要精确匹配 |
| 中文文本 | gse 或 trigram | 正确的词段分割 |
| 日语文本 | kagome_ja 或 trigram | 正确的形态分析 |
| 韩语文本 | kagome_kr 或 trigram | 正确的形态分析 |
性能注意事项
索引速度
word、lowercase、whitespace:速度快,性能相似。field:最快,因为不需要拆分。gse、trigram、kagome_*:由于更复杂的分割算法,速度较慢。
查询性能
- 简单的分词方法(
word、lowercase、whitespace):速度快。 - 带有通配符过滤器的
field:可能很慢,应谨慎使用。 - 特定于语言的方法:查询的性能与简单方法相似。
索引大小
- 更多的 token 会导致更大的索引。
field:创建最小的索引(每个值一个 token)。trigram:由于许多重叠的 trigram,创建最大的索引。
倒排索引
Weaviate 使用 倒排索引 来实现快速高效的过滤和搜索。倒排索引将值(如单词或数字)映射到包含它们的对象,以便加速所有基于属性的过滤(where 过滤器)和关键字搜索(bm25、hybrid)。禁用对您永远不会查询的属性的索引可以加快数据导入并减少磁盘使用量。
有关 indexFilterable、indexSearchable、indexRangeFilters 和 invertedIndexConfig 参数的更多详细信息,请参阅 参考:倒排索引。
向量配置
Weaviate 支持两种向量配置方法
- 单个向量集合:使用顶级参数(
vectorizer、vectorIndexType、vectorIndexConfig)为每个对象使用一个向量空间 - 多个命名向量:使用
vectorConfig参数为每个对象使用多个向量空间(推荐)
您不能在同一个集合中使用这两种方法。
vectorConfig使用 vectorConfig 参数允许您从每个集合的一个向量开始,并在创建集合后添加 新的命名向量。
向量配置参数
| 参数 | 类型 | 描述 | 默认值 | 可变 |
|---|---|---|---|---|
vectorizer | 字符串 | 要使用的向量化器模块(例如,text2vec-cohere)。设置为 none 以禁用自动向量化。可用模型提供程序 | 模块特定默认值 | 否 |
vectorIndexType | 字符串 | 向量索引类型:hnsw(默认)、flat 或 dynamic | hnsw | 否 |
vectorIndexConfig | 对象 | 您选择的 vectorIndexType 的配置设置 | 索引特定默认值 | 部分* |
vectorConfig | 对象 | 替代方案:定义多个命名向量空间 | null | 部分** |
↪ vectorConfig.<name>.vectorizer | 对象 | 此命名向量的向量化器配置(例如,{"text2vec-openai": {"properties": ["title"]}}) | (必需) | 否 |
↪ vectorConfig.<name>.vectorIndexType | 字符串 | 此命名向量的索引类型 | hnsw | 否 |
↪ vectorConfig.<name>.vectorIndexConfig | 对象 | 此命名向量的索引配置 | 索引特定默认值 | 部分* |
* 请参阅 向量索引可变参数 ** 可以在创建集合后添加新的命名向量
单个向量集合
如果您未在集合定义中显式定义 命名向量,Weaviate 会自动创建一个称为单个向量集合。这些向量在内部存储在名为 default 的向量下(这是一个保留的向量名称)。
要了解您的数据的哪些属性被向量化,请参阅配置语义索引部分。
代码示例 - 如何创建单个向量集合
此代码示例演示如何通过客户端库配置单个向量集合的向量化器参数
如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue。
from weaviate.classes.config import (
Configure,
DataType,
Property,
VectorDistances,
VectorFilterStrategy,
)
client.collections.create(
"Article",
vector_config=Configure.Vectors.text2vec_openai(
name="default", # (Optional) Set the name of the vector, default name is "default"
source_properties=["title", "body"], # (Optional) Set the source property(ies)
vector_index_config=Configure.VectorIndex.hnsw(
ef_construction=300,
distance_metric=VectorDistances.COSINE,
filter_strategy=VectorFilterStrategy.SWEEPING,
), # (Optional) Set vector index options
vectorize_collection_name=True, # (Optional) Set to True to vectorize the collection name
),
properties=[ # properties configuration is optional
Property(name="title", data_type=DataType.TEXT, vectorize_property_name=True),
Property(name="body", data_type=DataType.TEXT),
],
)
有关更多代码示例和配置指南,请访问操作指南:向量化器和向量索引配置指南。
多个向量嵌入(命名向量)
Weaviate 集合支持多个命名向量。
集合可以有多个 命名向量。
集合中的向量可以有自己的配置。每个向量空间可以设置自己的索引、自己的压缩算法和自己的向量化器。这意味着您可以对同一个对象使用不同的向量化模型,并应用不同的距离度量。
要使用命名向量,请调整您的查询以指定 向量搜索 或 混合搜索 查询的目标向量。
代码示例 - 如何创建多个命名向量
此代码示例演示如何通过客户端库配置多个命名向量
如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue。
from weaviate.classes.config import (
Configure,
DataType,
Property,
VectorDistances,
VectorFilterStrategy,
)
client.collections.create(
"Article",
vector_config=[
Configure.Vectors.text2vec_openai(
name="default", # (Optional) Set the name of the vector, default name is "default"
source_properties=[
"title",
"body",
], # (Optional) Set the source property(ies)
vector_index_config=Configure.VectorIndex.hnsw(
ef_construction=300,
distance_metric=VectorDistances.COSINE,
filter_strategy=VectorFilterStrategy.SWEEPING,
), # (Optional) Set vector index options
vectorize_collection_name=True, # (Optional) Set to True to vectorize the collection name
),
Configure.Vectors.text2vec_openai(
name="body_vectors",
source_properties=["body"],
vector_index_config=Configure.VectorIndex.flat(),
),
],
properties=[ # properties configuration is optional
Property(name="title", data_type=DataType.TEXT, vectorize_property_name=True),
Property(name="body", data_type=DataType.TEXT),
],
)
有关更多代码示例和配置指南,请访问操作指南:向量化器和向量索引配置指南。
模块配置
moduleConfig 参数允许您指定向量化器是否在向量计算中包含或排除集合名称(默认 true)。它还用于在集合级别指定重排序器和生成式 模型提供商。
示例模块配置 - JSON 对象
一个完整的 moduleConfig 对象的示例
"moduleConfig": {
"text2vec-contextionary": {
"vectorizeClassName": true // Include the collection name in vector calculation (default true)
}
},
向量索引
向量索引组织向量数据,使相似性搜索快速高效。索引不是将查询与每个向量进行比较,而是构建一个结构,快速缩小搜索范围到最相关的候选者。
有关 vectorIndexType 和 vectorIndexConfig 参数的更多详细信息,请参阅 参考:向量索引。
复制
复制配置可以使用定义来设置,通过 replicationConfig 参数。
| 参数 | 类型 | 描述 | 默认值 | 可变 |
|---|---|---|---|---|
factor | 整数 | 为每个分片维护的副本数。因子为 3 表示一个主节点和两个副本。 | 1 | 在 v1.25+ 中为否,在早期版本中为是 |
asyncEnabled | 布尔值 | 启用异步复制。在 v1.26 中添加 | false | 是 |
deletionStrategy | 字符串 | 处理复制中删除的策略。可以是 NoAutomatedResolution、DeleteOnConflict 或 TimeBasedResolution。在 v1.27 中添加 | "NoAutomatedResolution" | 是 |
示例复制配置 - JSON 对象
一个完整的 replicationConfig 对象的示例
{
"class": "Article",
"vectorizer": "text2vec-openai",
"replicationConfig": {
"factor": 3,
"asyncEnabled": false,
"deletionStrategy": "NoAutomatedResolution"
}
}
代码示例 - 如何配置复制
此代码示例演示如何通过客户端库配置复制参数
如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue。
from weaviate.classes.config import Configure, ReplicationDeletionStrategy
client.collections.create(
"Article",
replication_config=Configure.replication(
factor=3,
async_enabled=True,
deletion_strategy=ReplicationDeletionStrategy.TIME_BASED_RESOLUTION,
),
)
有关更多代码示例和配置指南,请访问操作指南:管理集合部分。
分片
分片通过集合定义中的 shardingConfig 对象进行配置。这些参数是不可变的,在创建集合后无法更改。
| 参数 | 类型 | 描述 | 默认值 | 可变 |
|---|---|---|---|---|
desiredCount | 整数 | 集合所需的物理分片数。如果此值大于集群节点的数量,则某些节点将托管多个分片。 | 节点数量 | 否 |
virtualPerPhysical | 整数 | 每个物理分片的虚拟分片数。虚拟分片有助于减少重新平衡期间的数据移动。 | 128 | 否 |
strategy | 字符串 | 确定对象属于哪个分片的策略。目前仅支持 "hash"。哈希基于 key 属性。 | "hash" | 否 |
key | 字符串 | 用于哈希以确定目标分片的属性。目前,只能使用对象的内部 UUID (_id)。 | "_id" | 否 |
function | 字符串 | 用于在 key 上使用的哈希函数。仅支持 "murmur3",它创建一个 64 位哈希,使冲突的可能性极低。 | "murmur3" | 否 |
actualCount | 整数 | (只读)创建的实际物理分片数。通常与 desiredCount 匹配,除非创建过程中出现问题。 | 1 | 否 |
desiredVirtualCount | 整数 | (只读)一个计算值,表示 desiredCount * virtualPerPhysical。 | 128 | 否 |
actualVirtualCount | 整数 | (只读)创建的实际虚拟分片数。 | 128 | 否 |
示例分片配置 - JSON 对象
一个完整的 shardingConfig 对象的示例
"shardingConfig": {
"virtualPerPhysical": 128,
"desiredCount": 1, // defaults to the amount of Weaviate nodes in the cluster
"actualCount": 1,
"desiredVirtualCount": 128,
"actualVirtualCount": 128,
"key": "_id",
"strategy": "hash",
"function": "murmur3"
}
代码示例 - 如何配置分片
此代码示例演示如何通过客户端库配置分片参数
如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue。
from weaviate.classes.config import Configure
client.collections.create(
"Article",
sharding_config=Configure.sharding(
virtual_per_physical=128,
desired_count=1,
desired_virtual_count=128,
),
)
有关更多代码示例和配置指南,请访问操作指南:管理集合部分。
多租户
多租户允许您在单个集合中隔离数据,对象与特定的租户关联。对于构建 SaaS 应用程序或任何需要严格数据分区系统的功能,这是一个有用的特性。
它以较低的开销提供数据隔离,而不是为每个租户创建一个单独的集合,在您拥有大量租户时,使其更具可扩展性。
要启用多租户,请在 multiTenancyConfig 对象中将 enabled 键设置为 true。此参数是不可变的,必须在创建时设置。
| 参数 | 类型 | 描述 | 默认值 | 可变 |
|---|---|---|---|---|
enabled | 布尔值 | 如果为 true,则为集合启用多租户。 | false | 否 |
autoTenantCreation | 布尔值 | 如果为 true,如果您尝试将对象插入到不存在的租户中,将创建一个新的租户。在 v1.25 中添加 | false | 是 |
autoTenantActivation | 布尔值 | 如果为 true,则如果对它们执行搜索、读取、更新或删除操作,则自动激活 INACTIVE 或 OFFLOADED 租户。在 v1.25.2 中添加 | false | 是 |
代码示例 - 如何配置多租户
此代码示例演示如何通过客户端库配置多租户参数
如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue。
from weaviate.classes.config import Configure
multi_collection = client.collections.create(
name="MultiTenancyCollection",
# Enable multi-tenancy on the new collection
multi_tenancy_config=Configure.multi_tenancy(enabled=True)
)
有关更多代码示例和配置指南,请访问操作指南:管理集合部分。
可变性
并非所有参数在创建集合后都是可变的。要修改不可变参数,请导出您的数据,创建一个新的集合,并将您的数据导入到其中。
可变参数
描述属性 描述invertedIndexConfigbm25bk1
cleanupIntervalSecondsstopwordsadditionspresetremovals
moduleConfig(仅生成式和重排序器模块,从1.26.8和v1.27.1)multiTenancyConfigautoTenantCreation(在v1.25.0中引入)autoTenantActivation(在v1.25.2中引入)
replicationConfigasyncEnabled(在v1.26.0中引入)factor(在v1.25或更高版本中不可变)deletionStrategy(在v1.27.0中引入)
vectorIndexConfigdynamicEfFactordynamicEfMindynamicEfMaxfilterStrategy(在v1.27.0中引入,适用于 HNSW)flatSearchCutoffbqenabledrescoreLimit
pqcentroidsenabledsegmentstrainingLimitencodertypedistribution
sqenabledrescoreLimittrainingLimit
skipvectorCacheMaxObjects
创建集合后,您可以 添加新属性。创建集合后,无法修改现有属性。您还可以 添加新的命名向量。
自动模式
“自动模式”功能通过从添加的数据中推断参数来自动生成集合定义。默认情况下已启用,可以通过在 docker-compose.yml 中将环境变量 AUTOSCHEMA_ENABLED 设置为 'false' 来禁用。
它将
- 如果将对象添加到不存在的集合,则创建一个集合。
- 添加正在添加的对象的任何缺失属性。
- 推断数组数据类型,例如
int[]、text[]、number[]、boolean[]、date[]和object[]。 - 推断
object和object[]数据类型的嵌套属性。 - 如果在添加的对象中包含与现有模式类型冲突的属性,则会引发错误。(例如,尝试将文本导入到模式中作为
int存在的字段)。
通常建议您禁用生产环境中的自动模式。
- 手动集合定义将提供更精确的控制。
- 在导入时推断数据结构存在性能损失。在某些情况下,例如复杂的嵌套属性,这可能是一项代价高昂的操作。
自动模式数据类型
为了满足您的需求,提供了额外的配置选项来帮助自动模式推断属性。
AUTOSCHEMA_DEFAULT_NUMBER=number- 为任何数值创建number列(而不是int等)。AUTOSCHEMA_DEFAULT_DATE=date- 为任何类似日期的值创建date列。
以下是不允许的
- 除非明确匹配受支持的两种类型
phoneNumber或geoCoordinates,否则禁止任何映射类型。 - 除非明确是引用类型,否则禁止任何数组类型。在这种情况下,Weaviate 需要解析信标并查看解析后的信标来自哪个集合,因为它需要集合名称才能修改模式。
集合计数限制
v1.30每个集合在索引、定义管理和存储方面都会增加开销。可以限制每个实例的集合数量。这有助于保持最佳性能和资源利用率。
- 默认限制:
-1(无限制)。 - 修改限制:使用
MAXIMUM_ALLOWED_COLLECTIONS_COUNT环境变量调整集合计数限制。
如果您的实例已经超过限制,Weaviate 将不允许创建任何新的集合。现有的集合不会被删除。
与其提高集合计数限制,不如考虑重新设计您的架构。有关更多详细信息,请参阅 入门指南:使用集合进行扩展限制。
集合别名
v1.32 中添加集合别名是 Weaviate 集合的替代名称,允许您通过替代名称引用集合。
别名名称必须是唯一的(不能与现有集合或其他别名匹配),并且多个别名可以指向同一个集合。您可以通过 客户端库以编程方式 或使用 REST 端点 设置集合别名。
为了管理集合别名,您需要拥有正确的 Collection aliases 权限。要管理别名引用的底层集合,您还需要该特定集合的 Collections 权限。
集合别名不能用于更新集合定义,包括
- 更新和添加属性
- 更新向量和倒排索引
- 配置分片和多租户
- 修改向量化器、生成器和重排序器配置
更多资源
问题和反馈
如果您有任何问题或反馈,请在 用户论坛 中告诉我们。
