Cortex Search and Hybrid Retrieval
Vector similarity is useful, but production search normally needs semantic meaning, exact keyword matches, metadata filters, reranking, and automatic index refreshes. Cortex Search packages these capabilities into a managed service.
1. Vector search versus Cortex Search
| Approach | Best fit |
|---|---|
| VECTOR columns and similarity SQL | Learning, custom experiments, or specialized ranking logic |
| Cortex Search Service | Low-latency enterprise search and RAG retrieval |
Cortex Search combines vector retrieval, keyword retrieval, and semantic reranking. This hybrid approach can find conceptual matches while preserving exact terms such as product codes or policy names.
2. Prepare searchable content
Each searchable row should contain one useful chunk of text plus metadata for filtering and citations.
CREATE OR REPLACE VIEW KNOWLEDGE_CHUNKS AS
SELECT
DOCUMENT_ID,
CHUNK_ID,
CHUNK_TEXT,
DEPARTMENT,
UPDATED_AT,
SOURCE_URL
FROM CURATED_DOCUMENT_CHUNKS
WHERE CHUNK_TEXT IS NOT NULL;
Keep chunks focused. Very large chunks reduce retrieval precision and increase the context sent to the generation model.
3. Create a search service
CREATE OR REPLACE CORTEX SEARCH SERVICE SUPPORT_KB_SEARCH
ON CHUNK_TEXT
ATTRIBUTES DEPARTMENT, UPDATED_AT
WAREHOUSE = AI_SEARCH_WH
TARGET_LAG = '1 hour'
AS (
SELECT
CHUNK_TEXT,
DOCUMENT_ID,
CHUNK_ID,
DEPARTMENT,
UPDATED_AT,
SOURCE_URL
FROM KNOWLEDGE_CHUNKS
);
The warehouse initializes and refreshes the service. Serving uses managed compute and has a separate cost profile.
4. Design retrieval filters
Metadata filters improve relevance and protect scope. Common examples include:
- department or product;
- document type;
- language;
- publication status;
- effective date;
- tenant or business unit.
Do not treat a filter as the only security boundary. Grant service access only to appropriate roles and design source objects with the required governance controls.
5. Measure search quality
Build a retrieval test set containing a question and the document or chunk expected in the top results. Track:
- recall at K;
- mean reciprocal rank;
- filter correctness;
- citation coverage;
- latency;
- no-result rate.
Tune chunking, source content, metadata, and scoring using the same test set. Avoid evaluating search only through generated answers because generation can hide retrieval failures.