Principle:1Panel dev MaxKB Vector Storage and Retrieval
| Knowledge Sources | |
|---|---|
| Domains | RAG, Vector_Database |
| Last Updated | 2026-10-10 00:00 GMT |
Overview
A data storage and retrieval paradigm that maps text into high-dimensional vector space, enabling similarity-based search for semantically related content.
Description
Vector storage and retrieval is the foundation of modern RAG systems. Text is embedded into dense vectors (typically 768–1536 dimensions) by an embedding model, then stored in a vector database. At query time, the user's question is embedded into the same space, and the system retrieves the nearest vectors (by cosine similarity or L2 distance). MaxKB uses PostgreSQL's pgvector extension as its vector store, storing embeddings alongside full-text search vectors (`SearchVector`) in the same `Embedding` table. This enables three search modes: pure embedding similarity, keyword (full-text), and blended (both combined).
Usage
Use this principle when designing:
- Knowledge base storage for RAG applications
- Hybrid search systems combining semantic and keyword matching
- Scalable vector retrieval with per-knowledge-base HNSW indexes
Theoretical Basis
The core operation is cosine similarity between query vector q and document vector d:
For efficient retrieval, Approximate Nearest Neighbor (ANN) algorithms like HNSW (Hierarchical Navigable Small World) are used. MaxKB leverages pgvector's HNSW indexes, querying per-knowledge-base to leverage partial indexes (`WHERE knowledge_id = '{k_id}'`).
For blended search, the comprehensive score combines embedding similarity with keyword relevance:
# Abstract algorithm description (NOT real implementation)
query_vec = embedding_model.embed(query_text)
# Search per knowledge base to leverage HNSW index
for kid in knowledge_id_list:
results = vector_search(
filter=knowledge_id == kid,
vector=query_vec,
top_n=top_n,
threshold=similarity,
)
# Merge and sort by similarity or comprehensive_score