Vector Search
Skill Profile
(Select at least one profile to enable specific modules)
Overview
Comprehensive guide for vector search implementation covering HNSW (Hierarchical Navigable Small World), IVF (Inverted File Index), Flat Index implementations, distance metrics (cosine, Euclidean, dot product), FAISS library usage, GPU acceleration, metadata filtering, hybrid search combining vector and keyword search, query optimization techniques, index building strategies, compression methods, scaling through sharding and replication, performance benchmarking, and evaluation metrics including Recall@K and MAP.
Why This Matters
Vector search enables finding similar items in high-dimensional space, which is fundamental to modern AI applications. It powers recommendation systems, semantic search, RAG, and many other AI/ML applications. Proper implementation of vector search algorithms, distance metrics, and optimization techniques can improve query performance by 10-100x while maintaining high recall. This skill is essential for building production-grade AI systems.
Core Concepts & Rules
1. Core Principles
- Follow established patterns and conventions
- Maintain consistency across codebase
- Document decisions and trade-offs
2. Implementation Guidelines
- Start with the simplest viable solution
- Iterate based on feedback and requirements
- Test thoroughly before deployment
Inputs / Outputs / Contracts
Skill Composition
- Depends on: None
- Compatible with: None
- Conflicts with: None
- Related Skills: None
Quick Start / Implementation Example
- Review requirements and constraints
- Set up development environment
- Implement core functionality following patterns
- Write tests for critical paths
- Run tests and fix issues
- Document any deviations or decisions
# Example implementation following best practices
def example_function():
# Your implementation here
pass
Assumptions
- Vectors are pre-computed using an embedding model
- Vector dimension is consistent across all vectors
- Sufficient memory is available for index storage
- GPU is available for GPU-accelerated operations
- Query volume justifies index optimization
Compatibility & Prerequisites
- Supported Versions:
- Python 3.8+
- Node.js 16+
- Modern browsers (Chrome, Firefox, Safari, Edge)
- Required AI Tools:
- Code editor (VS Code recommended)
- Testing framework appropriate for language
- Version control (Git)
- Dependencies:
- Language-specific package manager
- Build tools
- Testing libraries
- Environment Setup:
.env.example keys: API_KEY, DATABASE_URL (no values)
Test Scenario Matrix (QA Strategy)
| Type |
Focus Area |
Required Scenarios / Mocks |
| Unit |
Core Logic |
Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |
| Integration |
DB / API |
All external API calls or database connections must be mocked during unit tests |
| E2E |
User Journey |
Critical user flows to test |
| Performance |
Latency / Load |
Benchmark requirements |
| Security |
Vuln / Auth |
SAST/DAST or dependency audit |
| Frontend |
UX / A11y |
Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |
Technical Guardrails & Security Threat Model
1. Security & Privacy (Threat Model)
- Top Threats: Injection attacks, authentication bypass, data exposure
2. Performance & Resources
3. Architecture & Scalability
4. Observability & Reliability
Agent Directives & Error Recovery
(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)
- Thinking Process: Analyze root cause before fixing. Do not brute-force.
- Fallback Strategy: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.
- Self-Review: Check against Guardrails & Anti-patterns before finalizing.
- Output Constraints: Output ONLY the modified code block. Do not explain unless asked.
Definition of Done (DoD) Checklist
Anti-patterns / Pitfalls
- ⛔ Don't: Log PII, catch-all exception, N+1 queries
- ⚠️ Watch out for: Common symptoms and quick fixes
- 💡 Instead: Use proper error handling, pagination, and logging
Reference Links & Examples
- Internal documentation and examples
- Official documentation and best practices
- Community resources and discussions
Versioning & Changelog
- Version: 1.0.0
- Changelog:
- 2026-02-22: Initial version with complete template structure
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: vector-search3description: Comprehensive guide for vector search implementation covering HNSW (Hierarchical Use when this capability is needed.4---56# Vector Search78## Skill Profile9*(Select at least one profile to enable specific modules)*10- [ ] **DevOps**11- [x] **Backend**12- [ ] **Frontend**13- [ ] **AI-RAG**14- [ ] **Security Critical**1516## Overview17Comprehensive guide for vector search implementation covering HNSW (Hierarchical Navigable Small World), IVF (Inverted File Index), Flat Index implementations, distance metrics (cosine, Euclidean, dot product), FAISS library usage, GPU acceleration, metadata filtering, hybrid search combining vector and keyword search, query optimization techniques, index building strategies, compression methods, scaling through sharding and replication, performance benchmarking, and evaluation metrics including Recall@K and MAP.1819## Why This Matters20Vector search enables finding similar items in high-dimensional space, which is fundamental to modern AI applications. It powers recommendation systems, semantic search, RAG, and many other AI/ML applications. Proper implementation of vector search algorithms, distance metrics, and optimization techniques can improve query performance by 10-100x while maintaining high recall. This skill is essential for building production-grade AI systems.2122## Core Concepts & Rules2324### 1. Core Principles25- Follow established patterns and conventions26- Maintain consistency across codebase27- Document decisions and trade-offs2829### 2. Implementation Guidelines30- Start with the simplest viable solution31- Iterate based on feedback and requirements32- Test thoroughly before deployment333435## Inputs / Outputs / Contracts36#3738## Skill Composition39* **Depends on**: None40* **Compatible with**: None41* **Conflicts with**: None42* **Related Skills**: None4344## Quick Start / Implementation Example45461. Review requirements and constraints472. Set up development environment483. Implement core functionality following patterns494. Write tests for critical paths505. Run tests and fix issues516. Document any deviations or decisions5253```python54# Example implementation following best practices55def example_function():56 # Your implementation here57 pass58```596061## Assumptions62- Vectors are pre-computed using an embedding model63- Vector dimension is consistent across all vectors64- Sufficient memory is available for index storage65- GPU is available for GPU-accelerated operations66- Query volume justifies index optimization6768## Compatibility & Prerequisites6970* **Supported Versions**:71 - Python 3.8+72 - Node.js 16+73 - Modern browsers (Chrome, Firefox, Safari, Edge)74* **Required AI Tools**:75 - Code editor (VS Code recommended)76 - Testing framework appropriate for language77 - Version control (Git)78* **Dependencies**:79 - Language-specific package manager80 - Build tools81 - Testing libraries82* **Environment Setup**:83 - `.env.example` keys: `API_KEY`, `DATABASE_URL` (no values)848586## Test Scenario Matrix (QA Strategy)8788| Type | Focus Area | Required Scenarios / Mocks |89| :--- | :--- | :--- |90| **Unit** | Core Logic | Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |91| **Integration** | DB / API | All external API calls or database connections must be mocked during unit tests |92| **E2E** | User Journey | Critical user flows to test |93| **Performance** | Latency / Load | Benchmark requirements |94| **Security** | Vuln / Auth | SAST/DAST or dependency audit |95| **Frontend** | UX / A11y | Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |969798## Technical Guardrails & Security Threat Model99100### 1. Security & Privacy (Threat Model)101* **Top Threats**: Injection attacks, authentication bypass, data exposure102- [ ] **Data Handling**: Sanitize all user inputs to prevent Injection attacks. Never log raw PII103- [ ] **Secrets Management**: No hardcoded API keys. Use Env Vars/Secrets Manager104- [ ] **Authorization**: Validate user permissions before state changes105106### 2. Performance & Resources107- [ ] **Execution Efficiency**: Consider time complexity for algorithms108- [ ] **Memory Management**: Use streams/pagination for large data109- [ ] **Resource Cleanup**: Close DB connections/file handlers in finally blocks110111### 3. Architecture & Scalability112- [ ] **Design Pattern**: Follow SOLID principles, use Dependency Injection113- [ ] **Modularity**: Decouple logic from UI/Frameworks114115### 4. Observability & Reliability116- [ ] **Logging Standards**: Structured JSON, include trace IDs `request_id`117- [ ] **Metrics**: Track `error_rate`, `latency`, `queue_depth`118- [ ] **Error Handling**: Standardized error codes, no bare except119- [ ] **Observability Artifacts**:120 - **Log Fields**: timestamp, level, message, request_id121 - **Metrics**: request_count, error_count, response_time122 - **Dashboards/Alerts**: High Error Rate > 5%123124125## Agent Directives & Error Recovery126*(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)*127128- **Thinking Process**: Analyze root cause before fixing. Do not brute-force.129- **Fallback Strategy**: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.130- **Self-Review**: Check against Guardrails & Anti-patterns before finalizing.131- **Output Constraints**: Output ONLY the modified code block. Do not explain unless asked.132133134## Definition of Done (DoD) Checklist135136- [ ] Tests passed + coverage met137- [ ] Lint/Typecheck passed138- [ ] Logging/Metrics/Trace implemented139- [ ] Security checks passed140- [ ] Documentation/Changelog updated141- [ ] Accessibility/Performance requirements met (if frontend)142143144## Anti-patterns / Pitfalls145146* ⛔ **Don't**: Log PII, catch-all exception, N+1 queries147* ⚠️ **Watch out for**: Common symptoms and quick fixes148* 💡 **Instead**: Use proper error handling, pagination, and logging149150151## Reference Links & Examples152153* Internal documentation and examples154* Official documentation and best practices155* Community resources and discussions156157158## Versioning & Changelog159160* **Version**: 1.0.0161* **Changelog**:162 - 2026-02-22: Initial version with complete template structure163164---165> Converted and distributed by [TomeVault](https://tomevault.io/claim/amnadtaowsoam) — claim your Tome and manage your conversions.166<!-- tomevault:4.0:skill_md:2026-04-13 -->