Skip to content

Commit 3e6a2d4

Browse files
committed
feat: Add vector database support (v0.8.0-alpha)
1 parent a20785b commit 3e6a2d4

19 files changed

+7359
-1
lines changed

AI_MAINTAINABILITY_ANALYSIS.md

Lines changed: 897 additions & 0 deletions
Large diffs are not rendered by default.

FROM_BUILDER_OPTIMIZATION_EXPLAINED.md

Lines changed: 658 additions & 0 deletions
Large diffs are not rendered by default.

GITHUB_ISSUE_TEMPLATE.md

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# GitHub Issue 内容(待创建)
2+
3+
**标题**: feat: Add vector database support (v0.8.0-alpha)
4+
5+
**标签**: enhancement, v0.8.0
6+
7+
---
8+
9+
## 📋 Summary
10+
11+
Add vector database support to sqlxb, making it **the first unified ORM for both relational and vector databases**.
12+
13+
---
14+
15+
## ✨ Features
16+
17+
### Core Capabilities
18+
19+
-**Vector Type**: `sqlxb.Vector` with database compatibility (driver.Valuer, sql.Scanner)
20+
-**Distance Metrics**: Cosine Distance, L2 Distance, Inner Product
21+
-**Vector Search API**: `VectorSearch()` for unified query interface
22+
-**Distance Control**: `VectorDistance()` for flexible metrics
23+
-**Threshold Filtering**: `VectorDistanceFilter()` for distance-based filtering
24+
-**SQL Generator**: `SqlOfVectorSearch()` with hybrid query optimization
25+
-**Auto-Optimization**: Scalar filtering + vector search combined
26+
27+
### Key Advantages
28+
29+
1. **Unified API** (Zero learning curve)
30+
```go
31+
// MySQL (existing)
32+
sqlxb.Of(&Order{}).Eq("status", 1).Build().SqlOfSelect()
33+
34+
// VectorDB (new) - Same API!
35+
sqlxb.Of(&CodeVector{}).
36+
Eq("language", "golang").
37+
VectorSearch("embedding", queryVector, 10).
38+
Build().SqlOfVectorSearch()
39+
```
40+
41+
2. **Type-Safe** (Compile-time checks)
42+
3. **Auto-Ignore nil/0** (Dynamic queries made easy)
43+
4. **AI-Friendly** (Functional API)
44+
45+
---
46+
47+
## 🏗️ Implementation
48+
49+
### New Files (5)
50+
51+
| File | Lines | Purpose |
52+
|------|-------|---------|
53+
| `vector_types.go` | 169 | Vector type, distance metrics, calculations |
54+
| `cond_builder_vector.go` | 136 | CondBuilder vector methods |
55+
| `builder_vector.go` | 56 | BuilderX vector methods |
56+
| `to_vector_sql.go` | 195 | Vector SQL generator |
57+
| `vector_test.go` | 203 | Complete unit tests |
58+
59+
**Total**: ~760 lines of new code
60+
61+
### Modified Files (1)
62+
63+
- `oper.go`: +2 lines (added `VECTOR_SEARCH`, `VECTOR_DISTANCE_FILTER` constants)
64+
65+
### Unchanged Files
66+
67+
-`bb.go` - Perfect abstraction, no changes needed
68+
- ✅ All other core files - Zero modifications
69+
70+
---
71+
72+
## ✅ Quality Assurance
73+
74+
### Test Results
75+
76+
```
77+
Existing tests: 3/3 passed ✅
78+
- TestInsert
79+
- TestUpdate
80+
- TestDelete
81+
82+
Vector tests: 7/7 passed ✅
83+
- TestVectorSearch_Basic
84+
- TestVectorSearch_WithScalarFilter
85+
- TestVectorSearch_L2Distance
86+
- TestVectorDistanceFilter
87+
- TestVectorSearch_AutoIgnoreNil
88+
- TestVector_Distance
89+
- TestVector_Normalize
90+
91+
Total: 10/10 (100%)
92+
```
93+
94+
### Compatibility
95+
96+
- ✅ 100% backward compatible
97+
- ✅ Zero breaking changes
98+
- ✅ All existing code works unchanged
99+
100+
---
101+
102+
## 📚 Documentation
103+
104+
### Technical Documentation (100+ pages)
105+
106+
1. **VECTOR_README.md** - Documentation index
107+
2. **VECTOR_EXECUTIVE_SUMMARY.md** - Executive summary (12 pages)
108+
3. **VECTOR_DATABASE_DESIGN.md** - Complete technical design (40+ pages)
109+
4. **VECTOR_PAIN_POINTS_ANALYSIS.md** - Pain points analysis (30+ pages)
110+
5. **VECTOR_QUICKSTART.md** - Quick start guide (5 minutes)
111+
6. **VECTOR_RELEASE_NOTES.md** - Release notes
112+
7. **AI_MAINTAINABILITY_ANALYSIS.md** - AI maintainability analysis
113+
8. **FROM_BUILDER_OPTIMIZATION_EXPLAINED.md** - Complex code explanation
114+
9. **MAINTENANCE_STRATEGY.md** - 80/15/5 maintenance model
115+
116+
---
117+
118+
## 🎯 Use Cases
119+
120+
- ✅ Code search and recommendations
121+
- ✅ Document similarity retrieval
122+
- ✅ RAG (Retrieval-Augmented Generation) systems
123+
- ✅ Intelligent Q&A systems
124+
- ✅ Recommendation systems
125+
- ✅ Image/Audio search (after vectorization)
126+
127+
---
128+
129+
## 🚀 Example
130+
131+
```go
132+
package main
133+
134+
import "github.com/x-ream/sqlxb"
135+
136+
type CodeVector struct {
137+
Id int64 `db:"id"`
138+
Content string `db:"content"`
139+
Embedding sqlxb.Vector `db:"embedding"`
140+
Language string `db:"language"`
141+
Layer string `db:"layer"`
142+
}
143+
144+
func (CodeVector) TableName() string {
145+
return "code_vectors"
146+
}
147+
148+
func main() {
149+
queryVector := sqlxb.Vector{0.1, 0.2, 0.3, ...}
150+
151+
// Search similar code
152+
sql, args := sqlxb.Of(&CodeVector{}).
153+
Eq("language", "golang").
154+
Eq("layer", "repository").
155+
VectorSearch("embedding", queryVector, 10).
156+
Build().
157+
SqlOfVectorSearch()
158+
159+
// Execute: db.Select(&results, sql, args...)
160+
}
161+
```
162+
163+
**Output SQL**:
164+
```sql
165+
SELECT *, embedding <-> ? AS distance
166+
FROM code_vectors
167+
WHERE language = ? AND layer = ?
168+
ORDER BY distance
169+
LIMIT 10
170+
```
171+
172+
---
173+
174+
## 📊 Comparison
175+
176+
| Feature | sqlxb | Milvus | Qdrant | ChromaDB | pgvector |
177+
|---------|-------|--------|--------|----------|----------|
178+
| Unified API | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ |
179+
| ORM Support | ⭐⭐⭐⭐⭐ |||| ⭐⭐⭐ |
180+
| Type Safety | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐ |
181+
| Learning Curve | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ |
182+
| AI-Friendly | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ |
183+
184+
**Unique Value**: Only unified ORM for relational + vector databases
185+
186+
---
187+
188+
## 🎯 Next Steps
189+
190+
### Phase 2 (1 month)
191+
- Query optimizer enhancements
192+
- Batch vector operations
193+
- Performance benchmarking
194+
- More database adapters
195+
196+
### Phase 3 (3 months)
197+
- Production-grade quality
198+
- Complete toolchain
199+
- Community validation
200+
- Official v0.8.0 release
201+
202+
---
203+
204+
## 💬 Discussion
205+
206+
**Questions? Feedback? Suggestions?**
207+
208+
Comment below or join the discussion!
209+
210+
---
211+
212+
## 📄 Related
213+
214+
- Documentation: [VECTOR_README.md](./VECTOR_README.md)
215+
- Technical Design: [VECTOR_DATABASE_DESIGN.md](./VECTOR_DATABASE_DESIGN.md)
216+
- Pain Points: [VECTOR_PAIN_POINTS_ANALYSIS.md](./VECTOR_PAIN_POINTS_ANALYSIS.md)
217+
218+
---
219+
220+
**This is a major milestone for sqlxb - making it the AI-First ORM for the AI era!** 🚀
221+

0 commit comments

Comments
 (0)