# Lancedb

> LanceDB vector database patterns and best practices. Trigger: When using LanceDB vector database.

- Skill: `odjaramillo/lancedb` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add odjaramillo/lancedb`
- Raw SKILL.md: https://api.skillmd.com/api/skills/odjaramillo/lancedb/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: Apache-2.0
- Author: odjaramillo (https://skillmd.com/u/odjaramillo)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/odjaramillo/lancedb

---


## Critical Patterns

### Table Creation (REQUIRED)

```python
import lancedb

# ✅ ALWAYS: Define schema clearly
db = lancedb.connect("./my_db")

data = [
    {"id": 1, "text": "Hello world", "vector": [0.1, 0.2, ...]},
    {"id": 2, "text": "Goodbye world", "vector": [0.3, 0.4, ...]},
]

table = db.create_table("my_table", data)
```

### Vector Search (REQUIRED)

```python
# ✅ Search by vector similarity
results = table.search([0.1, 0.2, ...]).limit(10).to_list()

# ✅ With filter
results = table.search(query_vector) \
    .where("category = 'tech'") \
    .limit(5) \
    .to_list()
```

---

## Decision Tree

```
Need semantic search?      → Use vector search
Need exact match?          → Use where clause
Need hybrid search?        → Combine vector + filter
Need persistence?          → Use file-based connection
```

---

## Resources

- **Best Practices**: [best-practices.md](best-practices.md)

