在房地产行业构建企业知识库时,面对大量的企业资料,进行有效的数据标注是关键步骤。以下是具体的操作步骤、注意事项、推荐的软件,以及如何将标注后的元数据存储到向量数据库并进行搜索的示例。
json
{
"document_id": "12345",
"text": "该物业位于市中心,面积为120平方米。",
"annotations": [
{
"start": 1,
"end": 3,
"label": "位置"
},
{
"start": 12,
"end": 15,
"label": "面积"
}
],
"metadata": {
"source": "企业资料库",
"date": "2025-03-30"
}
}
python
from pymilvus import connections, FieldSchema, CollectionSchema, DataType, Collection
# 连接Milvus服务器
connections.connect("default", host="localhost", port="19530")
# 定义字段
fields = [
FieldSchema(name="id", dtype=DataType.INT64, is_primary=True),
FieldSchema(name="embedding", dtype=DataType.FLOAT_VECTOR, dim=128),
FieldSchema(name="metadata", dtype=DataType.JSON)
]
# 创建集合
schema = CollectionSchema(fields, description="企业资料向量集合")
collection = Collection(name="enterprise_docs", schema=schema)
# 插入数据
data = [
[1], # id
[[0.1, 0.2, ..., 0.128]], # embedding
[{"document_id": "12345", "text": "该物业位于市中心,面积为120平方米。"}] # metadata
]
collection.insert(data)
# 加载集合
collection.load()
# 搜索
query_embedding = [0.1, 0.2, ..., 0.128] # 查询文本的向量表示
search_params = {"metric_type": "L2", "params": {"nprobe": 10}}
results = collection.search([query_embedding], "embedding", search_params, limit=10, output_fields=["metadata"])
# 输出结果
for result in results[0]:
print(result.entity.get("metadata"))