跳至主要内容
前往文档
⌘U
Weaviate 数据库

使用 Weaviate 的 APIs 和工具开发 AI 应用

部署

部署、配置和维护 Weaviate 数据库

Weaviate Agents

使用 Weaviate 构建和部署智能代理

Weaviate Cloud

在云端管理和扩展 Weaviate

更多资源

集成
贡献者指南
活动 & 工作坊
Weaviate Academy

需要帮助?

Weaviate Logo询问 AI 助手⌘K
社区论坛

属性数据类型

创建属性时,您必须指定一个数据类型。Weaviate 接受以下类型。

可用数据类型

数组类型

通过在类型后添加 [] 来指定数据类型的数组(例如 texttext[])。请注意,并非所有数据类型都支持数组。

名称精确类型格式化数组 ([]) 可用 (示例)注意
文本字符串字符串["字符串一", "字符串二"]
布尔值布尔值true/false[true, false]
整数int64 (请参阅 说明)123[123, -456]
数字float640.0[0.0, 1.1]
日期字符串更多信息
UUID字符串"c8f8176c-6f9b-5461-8ab3-f3c7ce8c2f5c"["c8f8176c-6f9b-5461-8ab3-f3c7ce8c2f5c", "36ddd591-2dee-4e7e-a3cc-eb86d30a4303"]
地理坐标字符串更多信息
电话号码字符串更多信息
二进制大对象base64 编码字符串更多信息
对象对象{"child": "我嵌套了!"}[{"child": "我嵌套了!"}, {"child": "我也是嵌套的!"}]1.22 开始可用
交叉引用字符串更多信息
已弃用的类型
名称精确类型格式化数组可用 (示例)从以下版本弃用
字符串字符串"string"["字符串", "第二个字符串"]v1.19

有关每种数据类型的更多详细信息,请参见下文。

text

将此类型用于任何文本数据。

string 已弃用

v1.19 之前,Weaviate 支持额外的 datatype string,它通过标记化行为与 text 区分开来。从 v1.19 开始,此类型已被弃用,并且将在未来的版本中删除。

使用 text 代替 stringtext 支持通过 string 可用的标记化选项。

示例

属性定义

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
from weaviate.classes.config import Property, DataType, Configure, Tokenization

# Create collection
my_collection = client.collections.create(
name="Movie",
properties=[
Property(
name="title", data_type=DataType.TEXT, tokenization=Tokenization.LOWERCASE
),
Property(
name="movie_id", data_type=DataType.TEXT, tokenization=Tokenization.FIELD
),
Property(
name="genres", data_type=DataType.TEXT_ARRAY, tokenization=Tokenization.WORD
),
],
# Other properties are omitted for brevity
)

对象插入

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
# Create an object
example_object = {
"title": "Rogue One",
"movie_id": "ro123456",
"genres": ["Action", "Adventure", "Sci-Fi"],
}

obj_uuid = my_collection.data.insert(example_object)

boolean / int / number

booleanintnumber 类型用于存储布尔值、整数和浮点数,分别。

示例

属性定义

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
from weaviate.classes.config import Property, DataType

# Create collection
my_collection = client.collections.create(
name="Product",
properties=[
Property(name="name", data_type=DataType.TEXT),
Property(name="price", data_type=DataType.NUMBER),
Property(name="stock_quantity", data_type=DataType.INT),
Property(name="is_on_sale", data_type=DataType.BOOL),
Property(name="customer_ratings", data_type=DataType.NUMBER_ARRAY),
],
# Other properties are omitted for brevity
)

对象插入

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
# Create an object
example_object = {
"name": "Wireless Headphones",
"price": 95.50,
"stock_quantity": 100,
"is_on_sale": True,
"customer_ratings": [4.5, 4.8, 4.2],
}

obj_uuid = my_collection.data.insert(example_object)

注意:GraphQL 和 int64

虽然 Weaviate 支持 int64,但 GraphQL 当前仅支持 int32,并且不支持 int64。这意味着当前,使用 GraphQL 查询将不会返回 Weaviate 中具有大于 int32 的整数值的整数数据字段。我们正在努力解决此 问题。当前解决方法是使用 string 代替。

date

Weaviate 中的 dateRFC 3339 时间戳表示,格式为 date-time。时间戳包括时间和偏移量。

例如

  • "1985-04-12T23:20:50.52Z"
  • "1996-12-19T16:39:57-08:00"
  • "1937-01-01T12:00:27.87+00:20"

要添加一个日期列表作为单个实体,请使用格式为 date-time 的字符串数组。例如:["1985-04-12T23:20:50.52Z", "1937-01-01T12:00:27.87+00:20"]

在特定的客户端库中,您可能可以使用以下示例中显示的本机日期对象。

示例

属性定义

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
from weaviate.classes.config import Property, DataType
from datetime import datetime, timezone

# Create collection
my_collection = client.collections.create(
name="ConcertTour",
properties=[
Property(name="artist", data_type=DataType.TEXT),
Property(name="tour_name", data_type=DataType.TEXT),
Property(name="tour_start", data_type=DataType.DATE),
Property(name="tour_dates", data_type=DataType.DATE_ARRAY),
],
# Other properties are omitted for brevity
)

对象插入

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
# Create an object
# In Python, you can use the RFC 3339 format or a datetime object (preferably with a timezone)
example_object = {
"artist": "Taylor Swift",
"tour_name": "Eras Tour",
"tour_start": datetime(2023, 3, 17).replace(tzinfo=timezone.utc),
"tour_dates": [
# Use `datetime` objects with a timezone
datetime(2023, 3, 17).replace(tzinfo=timezone.utc),
datetime(2023, 3, 18).replace(tzinfo=timezone.utc),
# .. more dates
# Or use RFC 3339 format
"2024-12-07T00:00:00Z",
"2024-12-08T00:00:00Z",
],
}

obj_uuid = my_collection.data.insert(example_object)

uuid

专用的 uuiduuid[] 数据类型可以有效地存储 UUID

  • 每个 uuid 都是 128 位(16 字节)数字。
  • 可过滤索引使用 roaring 位图。
聚合/排序目前不可用

目前无法通过 uuiduuid[] 类型进行聚合或排序。

示例

属性定义

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
from weaviate.classes.config import Property, DataType
from weaviate.util import generate_uuid5

# Create collection
my_collection = client.collections.create(
name="Movie",
properties=[
Property(name="title", data_type=DataType.TEXT),
Property(name="movie_uuid", data_type=DataType.UUID),
Property(name="related_movie_uuids", data_type=DataType.UUID_ARRAY),
],
# Other properties are omitted for brevity
)

对象插入

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
# Create an object
example_object = {
"title": "The Matrix",
"movie_uuid": generate_uuid5("The Matrix"),
"related_movie_uuids": [
generate_uuid5("The Matrix Reloaded"),
generate_uuid5("The Matrix Revolutions"),
generate_uuid5("Matrix Resurrections"),
],
}

obj_uuid = my_collection.data.insert(example_object)

geoCoordinates

地理坐标可用于查找查询位置周围半径内的对象。地理坐标值存储为浮点数,并根据 十进制度 处理,符合 ISO 标准

要提供 geoCoordinates 属性,请将 latitudelongitude 指定为浮点十进制度。

示例

属性定义

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
from weaviate.classes.config import Property, DataType
from weaviate.classes.data import GeoCoordinate

# Create collection
my_collection = client.collections.create(
name="City",
properties=[
Property(name="name", data_type=DataType.TEXT),
Property(name="location", data_type=DataType.GEO_COORDINATES),
],
# Other properties are omitted for brevity
)

对象插入

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
# Create an object
example_object = {
"name": "Sydney",
"location": GeoCoordinate(latitude=-33.8688, longitude=151.2093),
}

obj_uuid = my_collection.data.insert(example_object)
限制

当前,地理坐标过滤仅限于从源位置的最近 800 个结果,这些结果将进一步减少任何其他过滤器条件和搜索参数。

如果您计划使用密集数据集,请考虑使用另一种策略,例如将地理哈希转换为 text 数据类型,并进一步过滤,例如使用 ContainsAny 过滤器。

phoneNumber

numberstring 字段不同,phoneNumber 输入将被标准化和验证。数据字段是一个包含多个字段的对象。

{
"phoneNumber": {
"input": "020 1234567", // Required. Raw input in string format
"defaultCountry": "nl", // Required if only a national number is provided, ISO 3166-1 alpha-2 country code. Only set if explicitly set by the user.
"internationalFormatted": "+31 20 1234567", // Read-only string
"countryCode": 31, // Read-only unsigned integer, numerical country code
"national": 201234567, // Read-only unsigned integer, numerical representation of the national number
"nationalFormatted": "020 1234567", // Read-only string
"valid": true // Read-only boolean. Whether the parser recognized the phone number as valid
}
}

有两个字段可以接受输入。input 必须始终设置,而 defaultCountry 仅在特定情况下才需要设置。存在两种可能的情况

  • 当您在 input 字段中输入国际号码(例如 "+31 20 1234567")时,无需输入 defaultCountry。底层的解析器将自动识别号码的国家/地区。
  • 当您输入国内号码(例如 "020 1234567")时,您需要在 defaultCountry 中指定国家/地区(在本例中为 "nl"),以便解析器能够正确地将号码转换为所有格式。defaultCountry 中的字符串应为 ISO 3166-1 alpha-2 国家/地区代码。

读取 phoneNumber 类型的字段时,Weaviate 还会添加其他只读字段,例如 internationalFormattedcountryCodenationalnationalFormattedvalid

示例

属性定义

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
from weaviate.classes.config import Property, DataType
from weaviate.classes.data import PhoneNumber

# Create collection
my_collection = client.collections.create(
name="Person",
properties=[
Property(name="name", data_type=DataType.TEXT),
Property(name="phone", data_type=DataType.PHONE_NUMBER),
],
# Other properties are omitted for brevity
)

对象插入

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
# Create an object
example_object = {
"name": "Ray Stantz",
"phone": PhoneNumber(number="212 555 2368", default_country="us"),
}

obj_uuid = my_collection.data.insert(example_object)

blob

blob 数据类型接受任何二进制数据。数据应为 base64 编码,并作为 string 传递。特性

  • Weaviate 不会对编码数据的类型做出任何假设。一个模块(例如 img2vec)可以根据需要检查文件头,但 Weaviate 本身不执行此操作。
  • 在存储时,数据将被 base64 解码(以便 Weaviate 更有效地存储它)。
  • 在提供服务时,数据将被 base64 编码(以便可以安全地作为 json 提供服务)。
  • 没有最大文件大小限制。
  • 无论设置如何,此 blob 字段始终在倒排索引中被跳过。这意味着您无法在 Weaviate GraphQL where 过滤器中按此 blob 字段进行搜索,并且没有相应的 valueBlob 字段。根据模块,此字段可用于模块特定的过滤器(例如 img2vec-neural 过滤器中的 nearImage)。

要获取图像的 base64 编码值,您可以运行以下命令 - 或使用 Weaviate 客户端中的辅助方法来执行此操作

cat my_image.png | base64

示例

属性定义

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
from weaviate.classes.config import Property, DataType

# Create collection
my_collection = client.collections.create(
name="Poster",
properties=[
Property(name="title", data_type=DataType.TEXT),
Property(name="image", data_type=DataType.BLOB),
],
# Other properties are omitted for brevity
)

对象插入

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
# Create an object
example_object = {
"title": "The Matrix",
"image": blob_string
}

obj_uuid = my_collection.data.insert(example_object)

object

v1.22 中添加

object 类型允许您将嵌套数据存储为 JSON 对象,该对象可以嵌套到任意深度。

例如,一个 Person 集合可以有一个 address 属性作为对象。它反过来可以包含嵌套属性,例如 streetcity

限制

目前,objectobject[] 数据类型属性未被索引和矢量化。

未来的计划包括索引嵌套属性的能力,例如允许对嵌套属性进行过滤和矢量化选项。

示例

属性定义

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
from weaviate.classes.config import Property, DataType

# Create collection
my_collection = client.collections.create(
name="Person",
properties=[
Property(name="name", data_type=DataType.TEXT),
Property(
name="home_address",
data_type=DataType.OBJECT,
nested_properties=[
Property(
name="street",
data_type=DataType.OBJECT,
nested_properties=[
Property(name="number", data_type=DataType.INT),
Property(name="name", data_type=DataType.TEXT),
],
),
Property(name="city", data_type=DataType.TEXT),
],
),
Property(
name="office_addresses",
data_type=DataType.OBJECT_ARRAY,
nested_properties=[
Property(name="office_name", data_type=DataType.TEXT),
Property(
name="street",
data_type=DataType.OBJECT,
nested_properties=[
Property(name="name", data_type=DataType.TEXT),
Property(name="number", data_type=DataType.INT),
],
),
],
),
],
# Other properties are omitted for brevity
)

对象插入

py docs  API 文档
更多信息文档中的代码片段反映了最新的客户端库和 Weaviate 数据库版本。请查看 发行说明 以获取特定版本。

如果某个片段无法工作或您有任何反馈,请打开一个 GitHub issue
# Create an object
example_object = {
"name": "John Smith",
"home_address": {
"street": {
"number": 123,
"name": "Main Street",
},
"city": "London",
},
"office_addresses": [
{
"office_name": "London HQ",
"street": {"number": 456, "name": "Oxford Street"},
},
{
"office_name": "Manchester Branch",
"street": {"number": 789, "name": "Piccadilly Gardens"},
},
],
}

obj_uuid = my_collection.data.insert(example_object)

cross-reference

交叉引用和查询性能

涉及交叉引用的查询可能比不涉及交叉引用的查询慢,尤其是在大规模情况下,例如对于多个对象或复杂查询。

首先,我们强烈建议您考虑是否可以避免在数据模式中使用交叉引用。作为可扩展的 AI 数据库,Weaviate 擅长使用向量、关键词和混合搜索进行复杂查询,包括过滤器。您可以通过重新思考数据模式来避免交叉引用,从而受益匪浅。

例如,与其创建带有交叉引用的单独的“作者”和“书籍”集合,不如考虑将作者信息直接嵌入到书籍对象中,并使用搜索和过滤器按作者特征查找书籍。

cross-reference 类型允许从一个对象创建到另一个对象的链接。这对于创建集合之间的关系很有用,例如将 Person 集合链接到 Company 集合。

cross-reference 类型对象默认情况下是 arrays。这允许您链接到给定集合的任意数量的实例(包括零)。

有关交叉引用的更多信息,请参阅 交叉引用。有关如何使用交叉引用的信息,请参阅 如何管理数据:交叉引用

注意事项

有效载荷中的格式

在原始有效载荷中(例如,REST 的 JSON 有效载荷),数据类型指定为数组(例如 ["text"]["text[]"]),因为这对于某些交叉引用规范是必需的。

更多资源

问题和反馈

如果您有任何问题或反馈,请在 用户论坛 中告诉我们。