You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Weaviate仅存储图像嵌入不存储原图像文件

如何配置Weaviate仅存储图像嵌入向量而不保存原图像文件

核心思路

无需自定义向量API或额外部署嵌入服务,只需调整Schema配置和数据导入流程,即可保留现成的img2vec-neural模块生成嵌入,同时让Weaviate仅存储向量和元数据(如S3路径、标签),不保存原图像文件。

步骤1:更新Schema配置

移除原Schema中存储图像的blob类型属性,添加用于关联S3原图像的路径字段,同时调整模块配置以适配新的导入方式:

const schemaConfig = {
    "class": "Product",
    "description": "Product images with embeddings stored in Weaviate, original files in S3",
    "moduleConfig": {
        "img2vec-neural": {} // 无需指定imageFields,不再存储图像属性
    },
    "properties": [
        {
            "dataType": ["text"],
            "description": "Label/description of the product image",
            "name": "labelName"
        },
        {
            "dataType": ["text"],
            "description": "S3 URL of the original product image",
            "name": "s3Url"
        }
    ],
    "vectorIndexType": "hnsw",
    "vectorizer": "img2vec-neural"
}

步骤2:调整数据导入流程

导入时临时将图像内容传递给img2vec-neural模块生成向量,但不将图像存入Weaviate,仅保存元数据和生成的向量。以Python客户端为例:

import weaviate
import base64

client = weaviate.Client("http://localhost:8080")

# 读取图像文件(可直接从S3下载后处理)
with open("target_image.jpg", "rb") as f:
    image_base64 = base64.b64encode(f.read()).decode("utf-8")

# 导入数据:仅存储元数据,通过vectorizeInput传递图像生成向量
client.data_object.create(
    data_object={
        "labelName": "Red running shoe",
        "s3Url": "s3://your-bucket/path/to/target_image.jpg"
    },
    class_name="Product",
    vectorizeInput={
        "image": image_base64  # 供img2vec生成向量,不会被存储
    }
)

步骤3:验证配置效果

  • 查询Weaviate中的Product对象,仅能看到labelName和s3Url字段,无图像Blob数据;
  • 向量搜索时,仍可通过上传图像生成向量,匹配Weaviate中的存储向量,返回元数据后从S3拉取原图像。

替代方案:预先生成向量再导入

若需要更灵活的控制,可直接调用i2v-neural服务生成向量,再手动导入Weaviate:

  1. 修改Schema,关闭自动向量化:
const schemaConfig = {
    "class": "Product",
    "description": "Product images with pre-generated embeddings",
    "properties": [
        {
            "dataType": ["text"],
            "description": "Label/description of the product image",
            "name": "labelName"
        },
        {
            "dataType": ["text"],
            "description": "S3 URL of the original product image",
            "name": "s3Url"
        }
    ],
    "vectorIndexType": "hnsw",
    "vectorizer": "none"
}
  1. 调用i2v-neural生成向量(示例curl命令):
curl -X POST http://localhost:8081/vectors \
  -H "Content-Type: image/jpeg" \
  --data-binary @target_image.jpg
  1. 将向量与元数据一起导入Weaviate:
client.data_object.create(
    data_object={
        "labelName": "Red running shoe",
        "s3Url": "s3://your-bucket/path/to/target_image.jpg"
    },
    class_name="Product",
    vector=[0.123, 0.456, ...]  # 从i2v-neural接口获取的向量值
)

内容的提问来源于stack exchange,提问作者Mansur

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 06:05:24