Skip to content

Commit 64b8155

Browse files
committed
initial push
0 parents  commit 64b8155

45 files changed

Lines changed: 7698 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
---
2+
# YAMS C++ Code Style
3+
# Based on LLVM style with modifications
4+
5+
BasedOnStyle: LLVM
6+
Language: Cpp
7+
Standard: c++20
8+
9+
# Indentation
10+
IndentWidth: 4
11+
TabWidth: 4
12+
UseTab: Never
13+
IndentCaseLabels: true
14+
IndentCaseBlocks: false
15+
NamespaceIndentation: None
16+
IndentPPDirectives: None
17+
IndentExternBlock: AfterExternBlock
18+
IndentGotoLabels: true
19+
20+
# Line Length
21+
ColumnLimit: 100
22+
23+
# Braces
24+
BreakBeforeBraces: Attach
25+
BraceWrapping:
26+
AfterCaseLabel: false
27+
AfterClass: false
28+
AfterControlStatement: Never
29+
AfterEnum: false
30+
AfterFunction: false
31+
AfterNamespace: false
32+
AfterStruct: false
33+
AfterUnion: false
34+
AfterExternBlock: true
35+
BeforeCatch: false
36+
BeforeElse: false
37+
BeforeLambdaBody: false
38+
BeforeWhile: false
39+
IndentBraces: false
40+
SplitEmptyFunction: true
41+
SplitEmptyRecord: true
42+
SplitEmptyNamespace: true
43+
44+
# Alignment
45+
AlignAfterOpenBracket: Align
46+
AlignArrayOfStructures: None
47+
AlignConsecutiveAssignments: None
48+
AlignConsecutiveBitFields: None
49+
AlignConsecutiveDeclarations: None
50+
AlignConsecutiveMacros: None
51+
AlignEscapedNewlines: Right
52+
AlignOperands: Align
53+
AlignTrailingComments: true
54+
55+
# Line Breaking
56+
AllowAllArgumentsOnNextLine: true
57+
AllowAllParametersOfDeclarationOnNextLine: true
58+
AllowShortBlocksOnASingleLine: Never
59+
AllowShortCaseLabelsOnASingleLine: false
60+
AllowShortEnumsOnASingleLine: true
61+
AllowShortFunctionsOnASingleLine: Inline
62+
AllowShortIfStatementsOnASingleLine: Never
63+
AllowShortLambdasOnASingleLine: All
64+
AllowShortLoopsOnASingleLine: false
65+
AlwaysBreakAfterReturnType: None
66+
AlwaysBreakBeforeMultilineStrings: false
67+
AlwaysBreakTemplateDeclarations: MultiLine
68+
BinPackArguments: true
69+
BinPackParameters: true
70+
BreakBeforeBinaryOperators: None
71+
BreakBeforeConceptDeclarations: true
72+
BreakBeforeTernaryOperators: true
73+
BreakConstructorInitializers: BeforeColon
74+
BreakInheritanceList: BeforeColon
75+
BreakStringLiterals: true
76+
77+
# Spaces
78+
SpaceAfterCStyleCast: false
79+
SpaceAfterLogicalNot: false
80+
SpaceAfterTemplateKeyword: true
81+
SpaceAroundPointerQualifiers: Default
82+
SpaceBeforeAssignmentOperators: true
83+
SpaceBeforeCaseColon: false
84+
SpaceBeforeCpp11BracedList: false
85+
SpaceBeforeCtorInitializerColon: true
86+
SpaceBeforeInheritanceColon: true
87+
SpaceBeforeParens: ControlStatements
88+
SpaceBeforeRangeBasedForLoopColon: true
89+
SpaceBeforeSquareBrackets: false
90+
SpaceInEmptyBlock: false
91+
SpaceInEmptyParentheses: false
92+
SpacesBeforeTrailingComments: 1
93+
SpacesInAngles: Never
94+
SpacesInCStyleCastParentheses: false
95+
SpacesInConditionalStatement: false
96+
SpacesInContainerLiterals: false
97+
SpacesInParentheses: false
98+
SpacesInSquareBrackets: false
99+
100+
# Other
101+
AccessModifierOffset: -4
102+
CompactNamespaces: false
103+
ConstructorInitializerIndentWidth: 4
104+
ContinuationIndentWidth: 4
105+
Cpp11BracedListStyle: true
106+
DerivePointerAlignment: false
107+
DisableFormat: false
108+
EmptyLineAfterAccessModifier: Never
109+
EmptyLineBeforeAccessModifier: LogicalBlock
110+
FixNamespaceComments: true
111+
IncludeBlocks: Preserve
112+
IndentRequires: false
113+
IndentWrappedFunctionNames: false
114+
InsertBraces: false
115+
InsertTrailingCommas: None
116+
KeepEmptyLinesAtTheStartOfBlocks: false
117+
LambdaBodyIndentation: Signature
118+
MaxEmptyLinesToKeep: 1
119+
PointerAlignment: Left
120+
QualifierAlignment: Leave
121+
ReferenceAlignment: Pointer
122+
ReflowComments: true
123+
RemoveBracesLLVM: false
124+
RequiresClausePosition: OwnLine
125+
SeparateDefinitionBlocks: Leave
126+
ShortNamespaceLines: 1
127+
SortIncludes: CaseInsensitive
128+
SortUsingDeclarations: true
129+
130+
# Penalties (for line breaking decisions)
131+
PenaltyBreakAssignment: 2
132+
PenaltyBreakBeforeFirstCallParameter: 19
133+
PenaltyBreakComment: 300
134+
PenaltyBreakFirstLessLess: 120
135+
PenaltyBreakOpenParenthesis: 0
136+
PenaltyBreakString: 1000
137+
PenaltyBreakTemplateDeclaration: 10
138+
PenaltyExcessCharacter: 1000000
139+
PenaltyIndentedWhitespace: 0
140+
PenaltyReturnTypeOnItsOwnLine: 60
141+
142+
# Include Categories
143+
IncludeCategories:
144+
- Regex: '^"yams/'
145+
Priority: 1
146+
SortPriority: 1
147+
- Regex: '^<tracy/'
148+
Priority: 2
149+
SortPriority: 2
150+
- Regex: '^<(sqlite3|sqlite_vec)'
151+
Priority: 3
152+
SortPriority: 3
153+
- Regex: '^<(spdlog|nlohmann|CLI11|magic_enum|toml|onnxruntime)'
154+
Priority: 4
155+
SortPriority: 4
156+
- Regex: '^<[^/]+>'
157+
Priority: 5
158+
SortPriority: 5
159+
- Regex: '.*'
160+
Priority: 6
161+
SortPriority: 6
162+
163+
# Macros
164+
AttributeMacros:
165+
- __capability
166+
ForEachMacros:
167+
- foreach
168+
- Q_FOREACH
169+
- BOOST_FOREACH
170+
IfMacros:
171+
- KJ_IF_MAYBE
172+
MacroBlockBegin: ''
173+
MacroBlockEnd: ''
174+
StatementAttributeLikeMacros:
175+
- Q_EMIT
176+
StatementMacros:
177+
- Q_UNUSED
178+
- QT_REQUIRE_VERSION
179+
WhitespaceSensitiveMacros:
180+
- STRINGIZE
181+
- PP_STRINGIZE
182+
- BOOST_PP_STRINGIZE
183+
- NS_SWIFT_NAME
184+
- CF_SWIFT_NAME

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Linker files
15+
*.ilk
16+
17+
# Debugger Files
18+
*.pdb
19+
20+
# Compiled Dynamic libraries
21+
*.so
22+
*.dylib
23+
*.dll
24+
25+
# Fortran module files
26+
*.mod
27+
*.smod
28+
29+
# Compiled Static libraries
30+
*.lai
31+
*.la
32+
*.a
33+
*.lib
34+
35+
# Executables
36+
*.exe
37+
*.out
38+
*.app
39+
40+
# debug information files
41+
*.dwo

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Trevon
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# sqlite-vec-cpp
2+
3+
Modern C++20/23 implementation of [sqlite-vec](https://github.com/asg017/sqlite-vec) vector similarity search for SQLite. Clean-room rewrite using zero-cost abstractions, template metaprogramming, and explicit error handling.
4+
5+
## Building
6+
7+
### Requirements
8+
9+
- **Compiler**: GCC 10+, Clang 12+, MSVC 19.29+ with C++20 support
10+
- **C++23**: Recommended for native `std::expected` (auto-detects and falls back to `tl::expected`)
11+
- **Dependencies**: SQLite3 ≥3.38.0 development headers
12+
- **Optional**: AVX2 (x86-64) or NEON (ARM64) for SIMD acceleration
13+
14+
### Meson (Recommended)
15+
16+
```bash
17+
meson setup build --buildtype=release -Dcpp_std=c++20
18+
meson compile -C build
19+
meson test -C build
20+
```
21+
22+
Build options:
23+
- `-Denable_simd=true|false|auto`: SIMD detection (default: auto)
24+
- `-Dcpp_std=c++20|c++23`: Standard version (default: c++23)
25+
- `-Denable_benchmarks=true`: Build performance benchmarks
26+
27+
## Performance
28+
29+
Micro-benchmarks (1M vector pairs, 384 dimensions, AVX2 enabled):
30+
| Operation | C (baseline) | C++ | Overhead |
31+
|-------------------|--------------|---------|----------|
32+
| L2 distance | 12.3 ms | 12.5 ms | +1.6% |
33+
| Cosine similarity | 15.1 ms | 15.3 ms | +1.3% |
34+
| Hamming distance | 8.7 ms | 8.8 ms | +1.1% |
35+
36+
Run benchmarks: `meson test -C build benchmark --benchmark`
37+
38+
## Design Constraints
39+
40+
This implementation maintains strict compatibility boundaries:
41+
42+
- **SQLite C API**: `sqlite3_vec_init()` entry point unchanged
43+
- **Virtual table interface**: vec0 schema and query semantics preserved
44+
- **Distance metrics**: L1, L2, cosine, Hamming only (no additions without upstream sync)
45+
- **Index structure**: Internal vec0 B-tree layout unchanged
46+
- **Performance**: Must match or exceed C baseline (no regressions allowed)
47+
48+
New C++ features (templates, concepts, RAII) are internal implementation details invisible to SQLite consumers.
49+
50+
## License
51+
52+
MIT License (same as original sqlite-vec)
53+
54+
**C++ modernization for YAMS**:
55+
Copyright (c) 2025 YAMS Contributors
56+
57+
See LICENSE file for complete terms.
58+
59+
## References
60+
61+
- **Upstream sqlite-vec**: https://github.com/asg017/sqlite-vec
62+
- **YAMS project**: https://github.com/trvon/yams
63+
- **C++20 Concepts**: https://en.cppreference.com/w/cpp/language/constraints
64+
- **std::expected**: https://en.cppreference.com/w/cpp/utility/expected
65+
66+
## Contributing
67+
68+
Follow YAMS contribution guidelines. Key requirements:
69+
70+
- All changes must pass `check-quality.sh`
71+
- Maintain performance parity (run benchmarks before/after)
72+
- Add tests for new functionality (minimum 80% coverage)
73+
- Update documentation for API changes
74+
75+
Submit issues or pull requests to the YAMS repository.

0 commit comments

Comments
 (0)