Loading...
Loading...
Compare original and translation side by side
| Database | Best For | Hosting | Filtering | Scale |
|---|---|---|---|---|
| Qdrant | High-performance, rich filtering, self-hosted | Self / Cloud | Excellent | Very High |
| Weaviate | Schema-first, hybrid search, multi-modal | Self / Cloud | Good | High |
| pgvector | Already on Postgres, simple use cases | Self | Good | Medium |
| Pinecone | Zero-ops managed, serverless | Managed only | Good | Very High |
| Chroma | Local dev, prototyping | Self only | Basic | Low-Medium |
| 数据库 | 适用场景 | 部署方式 | 过滤能力 | 扩展性 |
|---|---|---|---|---|
| Qdrant | 高性能、丰富过滤能力、自托管 | 自托管/云托管 | 优秀 | 极高 |
| Weaviate | Schema优先、混合搜索、多模态 | 自托管/云托管 | 良好 | 高 |
| pgvector | 已使用PostgreSQL、简单场景 | 自托管 | 良好 | 中等 |
| Pinecone | 零运维托管、无服务器 | 仅托管 | 良好 | 极高 |
| Chroma | 本地开发、原型验证 | 仅自托管 | 基础 | 低-中等 |
undefinedundefined
```yaml
```yamlundefinedundefinedfrom qdrant_client import QdrantClient
from qdrant_client.models import (
Distance, VectorParams, HnswConfigDiff,
ScalarQuantizationConfig, ScalarType, QuantizationConfig
)
client = QdrantClient("http://localhost:6333")from qdrant_client import QdrantClient
from qdrant_client.models import (
Distance, VectorParams, HnswConfigDiff,
ScalarQuantizationConfig, ScalarType, QuantizationConfig
)
client = QdrantClient("http://localhost:6333")undefinedundefinedfrom qdrant_client.models import Filter, FieldCondition, MatchValue, Rangefrom qdrant_client.models import Filter, FieldCondition, MatchValue, Rangeundefinedundefined-- Enable extension
CREATE EXTENSION IF NOT EXISTS vector;
-- Create table with vector column
CREATE TABLE documents (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
content TEXT NOT NULL,
embedding VECTOR(1536),
metadata JSONB DEFAULT '{}',
tenant_id TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Create HNSW index (faster queries, more memory)
CREATE INDEX ON documents
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);
-- Create IVFFlat index (less memory, slower build)
-- CREATE INDEX ON documents
-- USING ivfflat (embedding vector_cosine_ops)
-- WITH (lists = 100);
-- Semantic search with metadata filtering
SELECT id, content, metadata,
1 - (embedding <=> $1::vector) AS similarity
FROM documents
WHERE tenant_id = 'acme-corp'
AND metadata->>'doc_type' = 'contract'
ORDER BY embedding <=> $1::vector
LIMIT 10;undefined-- 启用扩展
CREATE EXTENSION IF NOT EXISTS vector;
-- 创建带向量列的表
CREATE TABLE documents (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
content TEXT NOT NULL,
embedding VECTOR(1536),
metadata JSONB DEFAULT '{}',
tenant_id TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- 创建HNSW索引(查询更快,占用内存更多)
CREATE INDEX ON documents
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);
-- 创建IVFFlat索引(占用内存更少,构建更慢)
-- CREATE INDEX ON documents
-- USING ivfflat (embedding vector_cosine_ops)
-- WITH (lists = 100);
-- 带元数据过滤的语义搜索
SELECT id, content, metadata,
1 - (embedding <=> $1::vector) AS similarity
FROM documents
WHERE tenant_id = 'acme-corp'
AND metadata->>'doc_type' = 'contract'
ORDER BY embedding <=> $1::vector
LIMIT 10;undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined| Issue | Cause | Fix |
|---|---|---|
| Slow queries | No HNSW index built yet | Wait for indexing; check |
| High RAM usage | Vectors in memory | Enable |
| Poor recall | Low | Increase |
| pgvector slow | Using IVFFlat without vacuum | Run |
| Weaviate OOM | Too many objects | Enable async indexing; increase heap |
| 问题 | 原因 | 解决方法 |
|---|---|---|
| 查询缓慢 | 尚未构建HNSW索引 | 等待索引完成;检查 |
| 内存占用过高 | 向量存储在内存中 | 启用 |
| 召回率低 | 搜索参数 | 在查询时提高 |
| pgvector查询缓慢 | 使用IVFFlat但未执行vacuum | 运行 |
| Weaviate内存溢出 | 对象数量过多 | 启用异步索引;增加堆内存 |
tenant_iddoc_typeon_diskalways_ramtenant_iddoc_typeon_diskalways_ram