慣性聚合 高效追蹤和閱讀你感興趣的部落格、新聞、科技資訊
閱讀原文 在慣性聚合中打開

推薦訂閱源

博客园 - 司徒正美
V
V2EX
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
月光博客
月光博客
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python)
AI原生數據庫向量數據庫 - 用戶文檔
Luis M · 2026-05-24 · via DEV Community

SynapCores 向量資料庫 - 用戶文檔

文檔日期: 2025年9月1日
版本: 1.0 (公開版)
狀態: 已準備生產


執行摘要

SynapCores 提供雲原生向量資料庫功能,具備先進索引、相似度搜尋和 AI 驅動的嵌入生成。本文件說明了如何將 SynapCores 整合到您的應用程式中,以實現語義搜尋、推薦和 AI 驅動的功能.

目錄

  1. 概覽
  2. 開始使用
  3. 嵌入生成
  4. 距離度量
  5. 索引策略
  6. CRUD 操作
  7. SQL 整合
  8. REST API
  9. 最佳實踐
  10. 常見應用場景

概述

SynapCores 融合傳統 SQL 資料庫功能與原生向量運算,讓您能夠:

  • 儲存和搜尋高維嵌入
  • 執行語義相似性搜尋
  • 執行結合關係和向量數據的混合查詢
  • 直接在數據庫中生成嵌入
  • 擴展至百萬級向量,查詢延遲低於100毫秒

主要功能

向量運算:

  • 多個距離度量(餘弦、歐氏、點積、曼哈頓)
  • 使用HNSW進行快速近似搜尋的先進索引
  • 精確和近似最近鄰居搜尋
  • 批量操作以實現高吞吐量

SQL整合:

  • 原生向量數據類型
  • 可在SQL查詢中調用的AI函數
  • 單一查詢中結合向量與關係數據
  • 標準SQL語法與向量擴展

企業功能

  • ACID交易
  • 自動數據持續性
  • 多租戶隔離
  • 高可用性

開始使用

1. 建立帳戶

https://synapcores.com註冊以獲取您的API憑據.

2. 獲取API Token

創建賬戶後,從您的儀表板生成API token:

# Your API token will look like this
export SYNAPCORES_TOKEN="sc_live_abc123xyz..."

進入全螢幕模式 退出全螢幕模式

3. 連接到您的資料庫

套接字連接(SQL介面):

# Connection via SynapCores native protocol
synapcores://username:password@your-instance.synapcores.com:5433/your_database

進入全螢幕模式 離開全螢幕模式

REST API:

# Base URL
https://api.synapcores.com/api/v1

進入全螢幕模式 離開全螢幕模式

連接方法:

  • 原生套接字協議: 用於 SQL 查詢和高性能操作
  • REST API: 跨語言 HTTP 基礎存取

4. 建立您的第一個向量空間

使用 SQL:

SELECT create_vector_space('products', 384, 'cosine');

進入全螢幕模式 離開全螢幕模式

使用 REST API:

curl -X POST https://api.synapcores.com/api/v1/vectors/collections \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "products",
    "dimensions": 384,
    "distance_metric": "cosine",
    "index_type": "hnsw"
  }'

進入全螢幕模式 離開全螢幕模式


嵌入生成

支援型號

SynapCores 提供內建嵌入生成,有多種型號選項:

型號 維度 適合 速度
MiniLM 384 通用文本,快速處理 ⚡⚡⚡ 快速
BERT Base 768 高品質的語義理解 ⚡⚡ 中等
BERT 大型 1024 最大嵌入品質 ⚡ 更慢

使用

在 SQL 中產生嵌入:

-- Use default model (MiniLM)
SELECT EMBED('wireless headphones');

-- Specify model explicitly
SELECT EMBED('wireless headphones', 'minilm');
SELECT EMBED('wireless headphones', 'bert-base');
SELECT EMBED('wireless headphones', 'bert-large');

進入全螢幕模式 離開全螢幕模式

在數據插入期間:

INSERT INTO products (name, description, embedding)
VALUES (
    'Bluetooth Headphones',
    'Premium wireless audio device',
    EMBED('Bluetooth Headphones Premium wireless audio device')
);

進入全螢幕模式 離開全螢幕模式

批量處理:

-- Generate embeddings for existing data
UPDATE products
SET embedding = EMBED(name || ' ' || description)
WHERE embedding IS NULL;

進入全螢幕模式 離開全螢幕模式


距離度量

選擇正確的度量

1.餘弦相似度(建議用於文本)

最佳用於:文本嵌入、語義搜尋、文件相似度

範圍:[-1, 1],其中1代表最相似

使用場景:比較文件、產品或基於文本的內容

SELECT COSINE_SIMILARITY(vector1, vector2) as similarity
FROM comparisons;

進入全螢幕模式 退出全螢幕模式

範例:尋找相似的產品描述

2. 歐幾里得距離 (L2)

最適用於:空間數據、圖像嵌入

範圍:[0, ∞],其中 0 = 相同

:比較空間坐標或圖像特徵

SELECT EUCLIDEAN_DISTANCE(vector1, vector2) as distance
FROM comparisons;

進入全螢幕模式 退出全螢幕模式

範例: 找尋類似圖片

3. 點積

最佳用於: 推薦系統

範圍: (-∞, ∞)

當您: 使用標準化向量計算相關性分數

SELECT INNER_PRODUCT(vector1, vector2) as score
FROM comparisons;

進入全螢幕模式 退出全螢幕模式

範例: 使用者-物品推薦

4. 曼哈頓距離 (L1)

最適應: 稀疏高維數據

範圍: [0, ∞]

: 處理稀疏特徵向量

SELECT MANHATTAN_DISTANCE(vector1, vector2) as distance
FROM comparisons;

全螢幕模式 退出全螢幕模式


索引策略

平面索引(精確搜尋)

特性:

  • 保證100%回憶率(精確結果)
  • 搜尋每個向量(暴力搜尋)
  • 適合小數據集

何時使用:

  • < 10,000個向量
  • 當需要精確結果時
  • 驗證和基準測試

性能:1-10毫秒(小型數據集)

-- Create with flat index (default)
SELECT create_vector_space('small_collection', 384, 'cosine');

進入全屏模式 退出全屏模式

HNSW 索引(快速近似搜索)

特性

  • 基於圖的近似最近鄰居搜索
  • 比扁平索引快 10-100 倍
  • 可調整準確度與速度

何時使用

  • 10K+ 維度
  • 生產應用
  • 需要低於 100ms 延遲時

性能:即使有數百萬維度,5-50ms

-- Create with HNSW index
SELECT create_vector_space('large_collection', 384, 'cosine', 'hnsw');

進入全屏模式 退出全螢幕模式

索引選擇指南

向量數量 建議索引 預期延遲
< 10K 扁平 1-10ms
10K - 100K HNSW 5-20ms
100K - 1M HNSW 10-50ms
1M+ HNSW 20-100ms

CRUD 操作

1. 建立向量空間

初始化新的向量集合:

SQL:

SELECT create_vector_space(
    'products',     -- Space name
    384,            -- Dimensions
    'cosine'        -- Distance metric
);

進入全螢幕模式 退出全螢幕模式

REST API:

curl -X POST https://api.synapcores.com/api/v1/vectors/collections \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "products",
    "dimensions": 384,
    "distance_metric": "cosine",
    "index_type": "hnsw"
  }'

進入全螢幕模式 退出全螢幕模式

回應:

{
  "status": "success",
  "data": {
    "name": "products",
    "dimensions": 384,
    "distance_metric": "cosine",
    "index_type": "hnsw",
    "created_at": "2025-09-01T10:00:00Z"
  }
}

進入全螢幕模式 退出全螢幕模式


2. 插入向量

單一插入帶自動產生的ID

SQL:

INSERT INTO vector_spaces.products (values, metadata)
VALUES (
    EMBED('Wireless Bluetooth Headphones'),
    '{"product_id": "12345", "category": "electronics"}'::JSON
);

進入全螢幕模式 離開全螢幕模式

REST API:

curl -X POST https://api.synapcores.com/api/v1/vectors/collections/products/vectors \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "vectors": [{
      "values": [0.1, 0.2, 0.3, ...],
      "metadata": {
        "product_id": "12345",
        "category": "electronics"
      }
    }]
  }'

進入全螢幕模式 離開全螢幕模式

使用自訂 ID 插入

SQL:

INSERT INTO vector_spaces.products (id, values, metadata)
VALUES (
    'prod_12345',
    EMBED('Wireless Bluetooth Headphones'),
    '{"category": "electronics"}'::JSON
);

進入全螢幕模式 離開全螢幕模式

批量插入(建議用於大量數據)

SQL:

-- Insert multiple vectors efficiently
INSERT INTO vector_spaces.products (values, metadata)
SELECT
    EMBED(description),
    JSON_BUILD_OBJECT('product_id', product_id, 'category', category)
FROM products
WHERE embedding IS NULL
LIMIT 1000;

進入全螢幕模式 退出全螢幕模式

REST API:

curl -X POST https://api.synapcores.com/api/v1/vectors/collections/products/vectors \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "vectors": [
      {"values": [0.1, ...], "metadata": {"product_id": "1"}},
      {"values": [0.2, ...], "metadata": {"product_id": "2"}},
      ...
    ]
  }'

進入全螢幕模式 退出全螢幕模式

效能技巧: 批量插入比單個插入快10-100倍。


搜索向量

语义搜索

SQL:

SELECT
    v.id,
    v.metadata->>'product_id' as product_id,
    v.metadata->>'category' as category,
    COSINE_SIMILARITY(v.values, EMBED('wireless headphones')) as similarity
FROM vector_spaces.products v
WHERE COSINE_SIMILARITY(v.values, EMBED('wireless headphones')) > 0.7
ORDER BY similarity DESC
LIMIT 10;

進入全螢幕模式 退出全螢幕模式

REST API:

curl -X POST https://api.synapcores.com/api/v1/vectors/collections/products/search \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query_text": "wireless headphones",
    "k": 10,
    "threshold": 0.7,
    "include_metadata": true
  }'

進入全螢幕模式 退出全螢幕模式

回應:

{
  "status": "success",
  "data": [
    {
      "id": "prod_12345",
      "score": 0.95,
      "metadata": {
        "product_id": "12345",
        "category": "electronics"
      }
    },
    {
      "id": "prod_67890",
      "score": 0.87,
      "metadata": {
        "product_id": "67890",
        "category": "electronics"
      }
    }
  ],
  "total_results": 2,
  "query_time_ms": 12
}

進入全螢幕模式 離開全螢幕模式

混合搜尋 (向量 + 過濾器)

結合語義搜尋與傳統 SQL 過濾器:

SELECT
    p.product_id,
    p.name,
    p.price,
    COSINE_SIMILARITY(p.embedding, EMBED('noise cancelling headphones')) as similarity
FROM products p
WHERE
    p.category = 'electronics'
    AND p.price BETWEEN 50 AND 200
    AND p.in_stock = true
    AND COSINE_SIMILARITY(p.embedding, EMBED('noise cancelling headphones')) > 0.7
ORDER BY similarity DESC, p.price ASC
LIMIT 20;

進入全螢幕模式 離開全螢幕模式

帶有元資料過濾器的搜尋 (REST API)

curl -X POST https://api.synapcores.com/api/v1/vectors/collections/products/search \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query_text": "wireless headphones",
    "k": 20,
    "threshold": 0.7,
    "filter": {
      "category": "electronics",
      "in_stock": true
    }
  }'

進入全螢幕模式 離開全螢幕模式


4. 更新向量

SQL:

UPDATE vector_spaces.products
SET
    values = EMBED('Updated product description'),
    metadata = JSON_BUILD_OBJECT(
        'product_id', '12345',
        'category', 'audio',
        'updated_at', CURRENT_TIMESTAMP
    )
WHERE id = 'prod_12345';

進入全螢幕模式 離開全螢幕模式

REST API:

curl -X PUT https://api.synapcores.com/api/v1/vectors/collections/products/vectors/prod_12345 \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "values": [0.1, 0.2, ...],
    "metadata": {
      "category": "audio",
      "updated_at": "2025-09-01T10:00:00Z"
    }
  }'

進入全螢幕模式 離開全螢幕模式


5. 刪除向量

SQL:

-- Delete by ID
DELETE FROM vector_spaces.products
WHERE id = 'prod_12345';

-- Delete by criteria
DELETE FROM vector_spaces.products
WHERE metadata->>'category' = 'discontinued';

進入全螢幕模式 退出全螢幕模式

REST API:

# Delete single vector
curl -X DELETE https://api.synapcores.com/api/v1/vectors/collections/products/vectors/prod_12345 \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN"

# Batch delete
curl -X POST https://api.synapcores.com/api/v1/vectors/collections/products/delete_batch \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ids": ["prod_12345", "prod_67890"]}'

進入全螢幕模式 退出全螢幕模式


6. 根據ID獲取向量

SQL:

SELECT id, values, metadata
FROM vector_spaces.products
WHERE id = 'prod_12345';

進入全螢幕模式 退出全螢幕模式

REST API:

curl -X GET https://api.synapcores.com/api/v1/vectors/collections/products/vectors/prod_12345 \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN"

進入全螢幕模式 離開全螢幕模式


SQL 整合

向量資料類型

使用原生向量欄位建立資料表:

CREATE TABLE products (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    description TEXT,
    price DECIMAL(10,2),
    category TEXT,
    embedding VECTOR(384)  -- 384-dimensional vector
);

進入全螢幕模式 離開全螢幕模式

AI 函數

EMBED() - 產生嵌入向量

-- Default model (MiniLM, 384 dimensions)
SELECT EMBED('wireless headphones');

-- Specify model
SELECT EMBED('wireless headphones', 'minilm');    -- 384d
SELECT EMBED('wireless headphones', 'bert-base'); -- 768d
SELECT EMBED('wireless headphones', 'bert-large'); -- 1024d

-- Use in INSERT
INSERT INTO products (name, description, embedding)
VALUES (
    'Bluetooth Headphones',
    'Premium wireless audio device',
    EMBED('Bluetooth Headphones Premium wireless audio device')
);

進入全螢幕模式 退出全螢幕模式

矢量相似度函數

COSINE_SIMILARITY():

SELECT
    product_id,
    name,
    COSINE_SIMILARITY(embedding, EMBED('wireless bluetooth headphones')) as similarity_score
FROM products
WHERE COSINE_SIMILARITY(embedding, EMBED('wireless bluetooth headphones')) > 0.7
ORDER BY similarity_score DESC
LIMIT 10;

進入全螢幕模式 退出全螢幕模式

EUCLIDEAN_DISTANCE():

SELECT
    id,
    EUCLIDEAN_DISTANCE(embedding, :query_vector) as distance
FROM image_embeddings
ORDER BY distance ASC
LIMIT 5;

進入全螢幕模式 退出全螢幕模式

INNER_PRODUCT():

SELECT
    user_id,
    item_id,
    INNER_PRODUCT(user_embedding, item_embedding) as relevance_score
FROM recommendations
WHERE relevance_score > 0.5
ORDER BY relevance_score DESC;

進入全螢幕模式 離開全螢幕模式

高階SQL模式

使用連接進行語義搜尋

-- Find customers who purchased similar products
SELECT
    c.customer_id,
    c.customer_name,
    p.product_name,
    o.order_date,
    COSINE_SIMILARITY(p.embedding, EMBED('premium headphones')) as relevance
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
JOIN order_items oi ON o.order_id = oi.order_id
JOIN products p ON oi.product_id = p.product_id
WHERE
    o.order_date > CURRENT_DATE - INTERVAL '90 days'
    AND COSINE_SIMILARITY(p.embedding, EMBED('premium headphones')) > 0.75
ORDER BY relevance DESC, o.order_date DESC
LIMIT 50;

進入全螢幕模式 離開全螢幕模式

使用向量進行聚合

-- Average similarity by category
SELECT
    category,
    COUNT(*) as product_count,
    AVG(COSINE_SIMILARITY(embedding, EMBED('premium quality'))) as avg_relevance
FROM products
GROUP BY category
HAVING avg_relevance > 0.6
ORDER BY avg_relevance DESC;

進入全螢幕模式 離開全螢幕模式

帶有向量的子查詢

-- Find products similar to top sellers
WITH top_products AS (
    SELECT product_id, embedding
    FROM products p
    JOIN order_items oi ON p.product_id = oi.product_id
    GROUP BY p.product_id, p.embedding
    ORDER BY SUM(oi.quantity) DESC
    LIMIT 10
)
SELECT DISTINCT
    p.product_id,
    p.name,
    MAX(COSINE_SIMILARITY(p.embedding, tp.embedding)) as max_similarity
FROM products p
CROSS JOIN top_products tp
WHERE p.product_id NOT IN (SELECT product_id FROM top_products)
GROUP BY p.product_id, p.name
HAVING MAX(COSINE_SIMILARITY(p.embedding, tp.embedding)) > 0.8
ORDER BY max_similarity DESC
LIMIT 20;

Enter fullscreen mode Exit fullscreen mode


REST API

基礎 URL

https://api.synapcores.com/api/v1

Enter fullscreen mode Exit fullscreen mode

認證

所有請求都需要使用 Bearer token 進行認證:

Authorization: Bearer <your_api_token>

Enter fullscreen mode 退出全螢幕模式

端點

方法 端點 目的
GET /vectors/collections 列出所有集合
POST /vectors/collections 建立集合
GET /vectors/collections/:name 取得集合資訊
DELETE /vectors/collections/:name 刪除集合
POST /vectors/collections/:name/vectors 插入向量
GET /vectors/collections/:name/vectors/:id 透過ID取得向量
PUT /vectors/collections/:name/vectors/:id 更新向量
DELETE /vectors/collections/:name/vectors/:id 刪除向量
POST /vectors/collections/:name/search 搜尋向量
POST /vectors/collections/:name/search/batch 批次搜尋

完整工作流程範例

# 1. Create collection
curl -X POST https://api.synapcores.com/api/v1/vectors/collections \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "documents",
    "dimensions": 384,
    "distance_metric": "cosine",
    "index_type": "hnsw"
  }'

# 2. Insert documents
curl -X POST https://api.synapcores.com/api/v1/vectors/collections/documents/vectors \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "vectors": [{
      "id": "doc_001",
      "values": [0.1, 0.2, ...],
      "metadata": {"title": "Getting Started", "type": "guide"}
    }]
  }'

# 3. Search documents
curl -X POST https://api.synapcores.com/api/v1/vectors/collections/documents/search \
  -H "Authorization: Bearer $SYNAPCORES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query_text": "how to get started",
    "k": 10,
    "threshold": 0.7
  }'

進入全螢幕模式 離開全螢幕模式

設限

操作 上限 備註
每次插入的向量數量 1,000 對於較大的數據集,請使用批次操作
每批次搜索的查詢數量 100 將較大的批次拆分成多個請求
每分鐘的 API 請求次數 1,000 聯繫支援以獲取更高的限制

最佳實踐

1. 選擇嵌入維度

維度 模型 應用場景 取捨
384 MiniLM 通用型、高性价比 最佳平衡
768 BERT Base 更高质量的語義理解 2倍儲存成本
1024 BERT Large 關鍵應用程式的最高品質 3倍儲存成本

推薦: 開始使用 384 次元(MiniLM)以適用於大多數情況.

2. 批次操作

總是使用批次操作以:

  • 大量數據匯入
  • 定期重新索引
  • 數據遷移

性能提升:

  • 比單獨操作快10-100倍
  • 減少API調用開銷
  • 提升吞吐量

最佳批次大小:每個請求100-1000個向量

3. 查詢優化

有效使用過濾器

-- Good: Filter before vector search
SELECT *
FROM products
WHERE
    category = 'electronics'  -- Traditional filter first
    AND price < 200
    AND COSINE_SIMILARITY(embedding, EMBED('headphones')) > 0.7

進入全螢幕模式 退出全螢幕模式

快取常見查詢:

  • 快取應用程式中的熱門搜尋嵌入
  • 對相同查詢重用嵌入
  • 減少嵌入產生開銷

4. 錯誤處理

實作重試邏輯:

import time
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry

session = requests.Session()
retry = Retry(
    total=3,
    backoff_factor=0.3,
    status_forcelist=[429, 500, 502, 503, 504]
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('https://', adapter)

進入全螢幕模式 離開全螢幕模式

處理速率限制:

  • 檢查回應標頭中的速率限制資訊
  • 實現指數退避
  • 在高流量期間排隊請求

5. 監控與可觀察性

追蹤應用程式中的關鍵指標:

  • 查詢延遲(p50, p95, p99)
  • 搜尋準確性/相關性
  • 嵌入產生時間
  • API 錯誤率

記錄重要事件:

  • 失敗的嵌入產生
  • 慢速查詢 (> 100毫秒)
  • 速率限制觸發

常見應用場景

商務電子商務語義搜尋

-- Create product table with embeddings
CREATE TABLE products (
    product_id SERIAL PRIMARY KEY,
    name TEXT,
    description TEXT,
    category TEXT,
    price DECIMAL(10,2),
    embedding VECTOR(384)
);

-- Index products
INSERT INTO products (name, description, category, price, embedding)
SELECT
    name,
    description,
    category,
    price,
    EMBED(name || ' ' || description)
FROM product_catalog;

-- Search by semantic meaning
SELECT
    product_id,
    name,
    price,
    COSINE_SIMILARITY(embedding, EMBED('wireless headphones')) as relevance
FROM products
WHERE relevance > 0.7
ORDER BY relevance DESC
LIMIT 20;

Enter fullscreen mode Exit fullscreen mode

商務內容推薦

-- Find similar articles based on user reading history
WITH user_interests AS (
    SELECT AVG(a.embedding) as avg_embedding
    FROM user_reading_history urh
    JOIN articles a ON urh.article_id = a.article_id
    WHERE urh.user_id = :user_id
)
SELECT
    a.article_id,
    a.title,
    COSINE_SIMILARITY(a.embedding, ui.avg_embedding) as relevance
FROM articles a
CROSS JOIN user_interests ui
WHERE a.article_id NOT IN (
    SELECT article_id FROM user_reading_history WHERE user_id = :user_id
)
AND relevance > 0.6
ORDER BY relevance DESC
LIMIT 10;

Enter fullscreen mode Exit fullscreen mode

商務重複檢測

-- Find near-duplicate documents
SELECT
    d1.document_id as doc1_id,
    d2.document_id as doc2_id,
    COSINE_SIMILARITY(d1.embedding, d2.embedding) as similarity
FROM documents d1
JOIN documents d2 ON d1.document_id < d2.document_id
WHERE COSINE_SIMILARITY(d1.embedding, d2.embedding) > 0.95
ORDER BY similarity DESC;

Enter fullscreen mode Exit fullscreen mode

用例 4:客戶支援路由

-- Find similar resolved tickets
SELECT
    t.ticket_id,
    t.subject,
    t.resolution,
    COSINE_SIMILARITY(t.embedding, EMBED(:new_ticket_text)) as similarity
FROM support_tickets t
WHERE
    t.status = 'resolved'
    AND similarity > 0.8
ORDER BY similarity DESC
LIMIT 5;

進入全螢幕模式 離開全螢幕模式


故障排除

查詢性能緩慢

症狀:查詢耗時> 100毫秒

解決方案

  1. 驗證是否使用 HNSW 索引(檢查查詢計劃)
  2. 減少請求的結果數量(降低 k 值)
  3. 使用元數據過濾器來縮小搜尋空間
  4. 考慮使用低維度的嵌入(384 而不是 768)

高 API 錯誤率

症狀:頻繁出現 429(速率限制)或 5xx 錯誤

解決方案:

  1. 實現指數退避重試邏輯
  2. 使用批次操作而非個別請求
  3. 聯繫支援以增加速率限制
  4. 快取常用嵌入

預期之外的搜尋結果

症狀: 语义搜尋中出現無關結果

解決方案:

  1. 提高相似度閾值(嘗試使用0.8而不是0.7)
  2. 確認輸入文本是否正確嵌入
  3. 確認正在使用正確的嵌入模型
  4. 檢查元資料濾鏡的正確性

嵌入生成失敗 (Embedding Generation Failures)

症狀: EMBED() 函數錯誤或超時

解決方案:

  1. 確認文字長度小於512個token
  2. 檢查特殊字元或編碼問題
  3. 使用指數退避重試
  4. 若錯誤持續請聯繫支援

客戶庫

Python

import requests

class SynapCoresClient:
    def __init__(self, api_token):
        self.base_url = "https://api.synapcores.com/api/v1"
        self.headers = {
            "Authorization": f"Bearer {api_token}",
            "Content-Type": "application/json"
        }

    def search(self, collection, query_text, k=10, threshold=0.7):
        response = requests.post(
            f"{self.base_url}/vectors/collections/{collection}/search",
            headers=self.headers,
            json={
                "query_text": query_text,
                "k": k,
                "threshold": threshold
            }
        )
        return response.json()

# Usage
client = SynapCoresClient("your_api_token")
results = client.search("products", "wireless headphones", k=10)

進入全螢幕模式 退出全螢幕模式

JavaScript/TypeScript

class SynapCoresClient {
    constructor(apiToken) {
        this.baseUrl = 'https://api.synapcores.com/api/v1';
        this.headers = {
            'Authorization': `Bearer ${apiToken}`,
            'Content-Type': 'application/json'
        };
    }

    async search(collection, queryText, k = 10, threshold = 0.7) {
        const response = await fetch(
            `${this.baseUrl}/vectors/collections/${collection}/search`,
            {
                method: 'POST',
                headers: this.headers,
                body: JSON.stringify({
                    query_text: queryText,
                    k,
                    threshold
                })
            }
        );
        return await response.json();
    }
}

// Usage
const client = new SynapCoresClient('your_api_token');
const results = await client.search('products', 'wireless headphones', 10);

進入全螢幕模式 離開全螢幕模式


性能預期

查詢延遲

資料集大小 索引類型 典型延遲
< 10K 向量 扁平 1-5毫秒
10K-100K 矢量 HNSW 5-20ms
100K-1M 矢量 HNSW 10-50ms
1M+ 矢量 HNSW 20-100ms

從 SynapCores 伺服器測量延遲。總客戶響應時間需加上網路延遲.

吞吐量

操作 預期吞吐量
單次插入 ~1,000 次/秒
批量插入 (100 個向量) ~10,000 個向量/秒
搜尋查詢 ~5,000 個查詢/秒

可擴展性限制

資源 限制 備註
每個空間的向量 10M+ 已測試且可生產使用
最大維度 4096 更高維度 = 更慢的搜尋
批次大小 1,000 個向量 每個 API 請求
API 請求速率限制 1,000 請求/分鐘 聯繫支援以獲得增加

支援與資源

文件

社區

支持

教學

  • 開始使用: 15分鐘內建立您的第一個語義搜尋
  • 生產部署: 部署至生產的最佳實踐
  • 進階模式: 混合搜尋、RAG 和多模態應用

定價

造訪 https://synapcores.com/pricing 以查詢最新定價細節.

免費層:

  • 10萬個向量
  • 每月100萬次API請求
  • 社群支援

專業層:

  • 10M 向量
  • 無限 API 請求
  • 電子郵件支援
  • 99.9% SLA

企業級方案

  • 無限向量
  • 專屬支援
  • 客製化 SLAs
  • 本地部署選項

限制

當前限制

  1. 維度變更: 建立後不可更改向量空間維度
  2. 度量變更: 建立空間後不可更改距離度量
  3. 最大維度: 最大4096維度
  4. 批次大小: 每次請求最多1,000個向量

計劃功能

  • 量化以降低儲存成本
  • GPU加速搜尋
  • 每份文件支援多向量
  • 進階過濾搜尋優化
  • 實時索引更新

結論

SynapCores 提供一個即時可用、雲原生的向量資料庫,包含:

語義搜尋 - 根據意義而非關鍵字尋找類似內容
SQL 整合 - 結合向量及關係查詢
易於使用 - 簡單的 API 和 SQL 函數
高效率 - 即使在規模擴展下查詢時間仍低於 100 毫秒
完全管理式 - 不需維護基礎設施

今日開始構建 AI 驅動應用程式於https://synapcores.com


文件版本: 1.0 (公開)
最後更新: 2025年9月1日
技術支援:support@synapcores.com


著作權所有 © 2025 SynapCores. 所有權利保留。表現特性可能因工作負載模式與網絡條件而有所不同.


最初發表於 synapcores.com — SynapCores 是一個免費、單二進制原生 AI 資料庫(向量 + 圖形 + SQL + LLM)。