ChatGPT 构建了我的 Milvus 模式

ChatGPT, LLM, GenAI, Python, Milvus, PyMilvus, Schema, Air Quality 聊天GPT,LLM,GenAI,Python,Milvus,PyMilvus,模式,空气质量

from pymilvus import (
connections,
FieldSchema,
CollectionSchema,
DataType,
Collection
)

# Connect to Milvus server
connections.connect(alias="default", host='localhost', port='19530')

# Define fields for the collection schema
fields = [
FieldSchema(name="locationId", dtype=DataType.INT64, is_primary=True, auto_id=False, description="Location ID"),
FieldSchema(name="locationName", dtype=DataType.VARCHAR, max_length=255, description="Name of the location"),
FieldSchema(name="publicLocationName", dtype=DataType.VARCHAR, max_length=255, description="Public name of the location"),
FieldSchema(name="latitude", dtype=DataType.FLOAT, description="Latitude of the location"),
FieldSchema(name="longitude", dtype=DataType.FLOAT, description="Longitude of the location"),
FieldSchema(name="offline", dtype=DataType.BOOL, description="Indicates if the location is offline"),
FieldSchema(name="pm01", dtype=DataType.FLOAT, description="Particulate matter (PM1.0)"),
FieldSchema(name="pm02", dtype=DataType.FLOAT, description="Particulate matter (PM2.5)"),
FieldSchema(name="pm10", dtype=DataType.FLOAT, description="Particulate matter (PM10)"),
FieldSchema(name="pm003Count", dtype=DataType.INT64, description="PM0.03 count"),
FieldSchema(name="atmp", dtype=DataType.FLOAT, description="Atmospheric pressure"),
FieldSchema(name="rhum", dtype=DataType.FLOAT, description="Relative humidity"),
FieldSchema(name="rco2", dtype=DataType.FLOAT, description="CO2 concentration"),
FieldSchema(name="tvoc", dtype=DataType.FLOAT, description="Total volatile organic compounds"),
FieldSchema(name="wifi", dtype=DataType.INT64, description="WiFi signal strength"),
FieldSchema(name="timestamp", dtype=DataType.VARCHAR, max_length=64, description="Timestamp in ISO 8601 format"),
FieldSchema(name="tvocIndex", dtype=DataType.INT64, description="TVOC index"),
FieldSchema(name="noxIndex", dtype=DataType.INT64, description="NOx index"),
FieldSchema(name="heatindex", dtype=DataType.FLOAT, description="Heat index"),
FieldSchema(name="publicPlaceName", dtype=DataType.VARCHAR, max_length=255, description="Public place name"),
FieldSchema(name="publicPlaceUrl", dtype=DataType.VARCHAR, max_length=512, description="Public place URL"),
FieldSchema(name="publicContributorName", dtype=DataType.VARCHAR, max_length=255, description="Public contributor name"),
FieldSchema(name="timezone", dtype=DataType.VARCHAR, max_length=64, description="Timezone"),
FieldSchema(name="model", dtype=DataType.VARCHAR, max_length=32, description="Model of the device"),
FieldSchema(name="firmwareVersion", dtype=DataType.VARCHAR, max_length=32, description="Firmware version")
]

# Create the collection schema
schema = CollectionSchema(fields, description="Environmental sensor data for a specific location")

# Create the collection
collection = Collection(name="environment_data", schema=schema)

print(f"Collection created: {collection.name}")

联系我们

如果你喜欢这篇博客文章,请考虑在GitHub上给我们一个星。也欢迎加入我们的Discord分享你在Milvus社区的经验。

2024-09-24 04:17:34 AI中文站翻译自原文