共用方式為


Microsoft Fabric 中 Cosmos DB 中的範例資料集

Microsoft Fabric 的 Cosmos DB 資料庫工作負載內建範例資料集,幫助你探索、學習並實驗 NoSQL 資料庫模式。 這組資料集代表一個電子商務情境,包含產品與顧客評論,展示不同實體類型如何共存於同一容器中。

有兩組樣本資料可供參考:

  • 標準範例資料:核心電子商務資料,含產品與評論
  • 向量樣本資料:強化版,包含使用 OpenAI 的文本嵌入 ada-002 模型生成的 1536 維向量嵌入,用於語意搜尋情境。

資料集概述

這兩個範例資料集都包含相同的電子商務資料,但有兩種文件類型。

  • 產品文件docType: "product")-包含名稱、描述、庫存、當前價格及該產品價格歷史內嵌陣列的個別產品。
  • 評論文件docType: "review")- 透過以下方式連結產品的顧客評論與評分 productId

向量樣本資料集是基於標準樣本資料集。 向量資料集中的產品文件包含一個額外的vectors屬性,該屬性具有1536維嵌入,用於語意搜尋功能。

備註

你可以在 Cosmos DB in Fabric - Samples Repository 的 Sample Datasets 資料夾中找到這兩個資料集,以及一個使用 OpenAI text-embedding-3-large 模型產生、512 維度的向量額外資料集

文件結構

產品文件結構

產品文件包含電子商務目錄中個別商品的詳細資訊:

房產 類型 說明
id string 以 GUID 格式呈現的產品唯一標識符
docType string 文件類型識別符,保持為 "product"
productId string 產品識別碼,與 id 產品文件相同
name string 產品顯示名稱
description string 詳細產品說明
categoryName string 產品類別(例如:「電腦、筆記型電腦」、「媒體」、「配件」)
inventory number 目前庫存商品數量
firstAvailable string 產品上市日期(ISO 8601格式)
currentPrice number 目前售價
priceHistory array 包含dateprice欄位的價格變動物件陣列
priceHistory[].date string ISO 8601格式價格變動的日期與時間
priceHistory[].price number 指定日期的價格
vectors array 僅向量樣本數據 - 1536 維向量嵌入

檢視文件結構

評論文件包含顧客回饋與產品評分:

房產 類型 說明
id string GUID 格式評論的唯一識別碼
docType string 文件類型識別器,一律 "review"
productId string 被評測產品的參考資料id
categoryName string 產品類別(繼承自評測中之產品)
customerName string 撰寫評論的顧客姓名
reviewDate string 審查提交日期(ISO 8601格式)
stars number 客戶給出的評分(1-5 分)
reviewText string 客戶的書面評論內容

備註

Cosmos DB 會自動為所有文件產生系統屬性(_rid, , _self_etag_attachments_ts, , )。

備註

如需 ISO 8601 格式的詳細資訊,請參閱 國際日期和時間標準。 如需 GUID 格式的詳細資訊,請參閱 通用唯一標識碼

範例文件

以下範例展示了兩個樣本資料集中文件的結構。

標準產品文件範例

{
  "id": "ae449848-3f15-4147-8eee-fe76cfcc6bb4",
  "docType": "product",
  "productId": "ae449848-3f15-4147-8eee-fe76cfcc6bb4",
  "name": "EchoSphere Pro ANC-X900 Premium Headphones",
  "description": "EchoSphere Pro ANC-X900 Premium Headphones deliver immersive sound with advanced 40mm drivers and Adaptive Hybrid Active Noise Cancellation. Bluetooth 5.3 ensures seamless connectivity.",
  "categoryName": "Accessories, Premium Headphones",
  "inventory": 772,
  "firstAvailable": "2024-01-01T00:00:00",
  "currentPrice": 454.87,
  "priceHistory": [
    {
      "date": "2024-01-01T00:00:00",
      "price": 349.0
    },
    {
      "date": "2024-08-01T00:00:00",
      "price": 363.0
    },
    {
      "date": "2025-04-01T00:00:00",
      "price": 408.14
    },
    {
      "date": "2025-08-01T00:00:00",
      "price": 454.87
    }
  ]
}

向量化產品文件範例

{
    "id": "ae449848-3f15-4147-8eee-fe76cfcc6bb4",
    "docType": "product",
    "productId": "ae449848-3f15-4147-8eee-fe76cfcc6bb4",
    "name": "EchoSphere Pro ANC-X900 Premium Headphones",
    "description": "EchoSphere Pro ANC-X900 Premium Headphones deliver immersive sound with advanced 40mm drivers and Adaptive Hybrid Active Noise Cancellation. Bluetooth 5.3 ensures seamless connectivity.",
    "categoryName": "Accessories, Premium Headphones",
    "inventory": 772,
    "firstAvailable": "2024-01-01T00:00:00",
    "currentPrice": 454.87,
    "priceHistory": [
      {
        "date": "2024-01-01T00:00:00",
        "price": 349.0
      },
      {
        "date": "2025-08-01T00:00:00",
        "price": 454.87
      }
    ],
    "vectors": [
      -0.02783808670938015,
      0.011827611364424229,
      -0.04711977392435074,
      // ... (1536 dimensions total)
      0.04251981899142265
    ]
}

審查文件範例

兩個樣本資料集的審查文件完全相同:

{
  "id": "fa799013-1746-4a7f-bd0f-2a95b2b76481",
  "docType": "review",
  "productId": "e847e069-d0f9-4fec-b42a-d37cd5b2f536",
  "categoryName": "Accessories, Premium Headphones",
  "customerName": "Emily Rodriguez",
  "reviewDate": "2025-03-02T00:00:00",
  "stars": 5,
  "reviewText": "Excellent sound quality! Premium build! This EchoSphere Pro ANC-X900 exceeded hopes."
}

如何使用範例數據

這兩組範例資料集都能幫助你練習在 Cosmos DB 中查詢、篩選和彙整資料。 混合文件類型為各種使用情境提供了真實的情境。

標準範例資料情境

  • 連結相關資料:連結產品評論,使用 productId
  • 分類分析:查詢產品與評論 categoryName
  • 評論分析:檢視顧客反饋模式與評分

常見的查詢模式

將所有產品歸類:

SELECT *
FROM c
WHERE 
  c.docType = "product" AND 
  c.categoryName = "Computers, Laptops"

取得特定產品的評價:

SELECT *
FROM c
WHERE 
  c.docType = "review" AND 
  c.productId = "77be013f-4036-4311-9b5a-dab0c3d022be"

向量樣本資料情境

  • 意相似性搜尋:利用向量嵌入尋找具有相似特徵的產品
  • 內容導向推薦:根據描述相似度產生產品推薦
  • 混合式查詢:結合傳統濾波器與向量相似度,提升結果

JSON 架構

以下 JSON 架構描述了兩個範例資料集中文件的結構。 利用這些架構驗證或產生類似資料,適用於你自己的 Cosmos DB 工作負載。

標準產品文件結構

{
  "type": "object",
  "properties": {
    "id": { "type": "string" },
    "docType": { "type": "string" },
    "productId": { "type": "string" },
    "name": { "type": "string" },
    "description": { "type": "string" },
    "categoryName": { "type": "string" },
    "inventory": { "type": "number" },
    "firstAvailable": { "type": "string" },
    "currentPrice": { "type": "number" },
    "priceHistory": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "date": { "type": "string" },
          "price": { "type": "number" }
        },
        "required": ["date", "price"]
      }
    }
  },
  "required": [
    "id", "docType", "productId", "name", "description", "categoryName", "inventory", "firstAvailable", "currentPrice", "priceHistory"
  ]
}

具向量支援的產品文件結構描述

{
  "type": "object",
  "properties": {
    "id": { "type": "string" },
    "docType": { "type": "string" },
    "productId": { "type": "string" },
    "name": { "type": "string" },
    "description": { "type": "string" },
    "categoryName": { "type": "string" },
    "inventory": { "type": "number" },
    "firstAvailable": { "type": "string" },
    "currentPrice": { "type": "number" },
    "priceHistory": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "date": { "type": "string" },
          "price": { "type": "number" }
        },
        "required": ["date", "price"]
      }
    },
    "vectors": {
      "type": "array",
      "items": { "type": "number" },
      "minItems": 1536,
      "maxItems": 1536
    }
  },
  "required": [
    "id", "docType", "productId", "name", "description", "categoryName", "inventory", "firstAvailable", "currentPrice", "priceHistory", "vectors"
  ]
}

檢視文件結構

{
  "type": "object",
  "properties": {
    "id": { "type": "string" },
    "docType": { "type": "string", "const": "review" },
    "productId": { "type": "string" },
    "categoryName": { "type": "string" },
    "customerName": { "type": "string" },
    "reviewDate": { "type": "string" },
    "stars": { "type": "number" },
    "reviewText": { "type": "string" }
  },
  "required": [
    "id", "docType", "productId", "categoryName", "customerName", 
    "reviewDate", "stars"
  ]
}