Documentation
¶
Index ¶
- type CompressModelProgress
- type CompressedProdVector
- type CompressedVector
- type Config
- type Document
- type EmbeddingFunc
- type Filter
- func And(filters ...Filter) Filter
- func Contains(field, substr string) Filter
- func Eq(field string, value any) Filter
- func Gt(field string, value float64) Filter
- func Gte(field string, value float64) Filter
- func In(field string, values ...any) Filter
- func Lt(field string, value float64) Filter
- func Lte(field string, value float64) Filter
- func Ne(field string, value any) Filter
- func Nin(field string, values ...any) Filter
- func NotContains(field, substr string) Filter
- func Or(filters ...Filter) Filter
- type IndexConfig
- type IndexType
- type KVCacheConfig
- type ModelConfig
- type QueryOptions
- type Result
- type RotationType
- type SafeTensorsFile
- func (sf *SafeTensorsFile) Close() error
- func (sf *SafeTensorsFile) Metadata() map[string]string
- func (sf *SafeTensorsFile) NumTensors() int
- func (sf *SafeTensorsFile) ReadRowFloat64(name string, row int) ([]float64, error)
- func (sf *SafeTensorsFile) Tensor(name string) (TensorInfo, bool)
- func (sf *SafeTensorsFile) TensorBytes(name string) ([]byte, error)
- func (sf *SafeTensorsFile) TensorNames() []string
- type SearchOptions
- type StoreConfig
- type StoreInfo
- type TQMTensorInfo
- type TQModelHeader
- type TensorInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompressModelProgress ¶
type CompressModelProgress func(tensorName string, tensorIdx, totalTensors int, rows, totalRows int)
CompressModelProgress reports compression progress. Called from the main goroutine with the current tensor and row counts.
type CompressedProdVector ¶
type CompressedProdVector struct {
CompressedVector
Signs []int8 // QJL sign bits, length = QJL projection dimension
ResidualNorm float32 // ‖residual‖₂
}
CompressedProdVector adds QJL data for unbiased inner product estimation.
type CompressedVector ¶
type CompressedVector struct {
Dim int // original dimension
Bits int // quantization bits per coordinate
Norm float32 // original L2 norm
Indices []uint8 // quantization indices (one per coordinate, values 0..2^bits-1)
}
CompressedVector is the output of TurboQuantMSE.Quantize(). It stores quantization indices and the original vector norm.
func (*CompressedVector) AppendBinary ¶
func (cv *CompressedVector) AppendBinary(dst []byte) []byte
AppendBinary appends the binary encoding to dst and returns the extended slice. Avoids allocation when dst has sufficient capacity.
func (*CompressedVector) MarshalBinary ¶
func (cv *CompressedVector) MarshalBinary() ([]byte, error)
MarshalBinary encodes a CompressedVector to a compact binary format. Layout: [dim:2][bits:1][norm:4][packed_indices:...]
func (*CompressedVector) Size ¶
func (cv *CompressedVector) Size() int
Size returns the serialized size in bytes.
func (*CompressedVector) UnmarshalBinary ¶
func (cv *CompressedVector) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes a CompressedVector from binary format.
type Config ¶
type Config struct {
Dim int // embedding dimension (required)
Bits int // bits per coordinate: 1-8 (default: 4)
Seed uint64 // rotation matrix seed (default: 42)
Rotation RotationType // rotation algorithm (default: RotationQR)
UseExactPDF bool // use exact Beta PDF for codebook (default: false, uses Gaussian approx)
}
Config controls quantizer behavior.
func (Config) WithDefaults ¶
WithDefaults returns a copy with zero fields filled to defaults.
type Document ¶
type Document struct {
ID string // unique identifier
Content string // original text for RAG (optional)
Data map[string]any // typed fields (VS2: data)
Embedding []float64 // raw embedding (nil = auto-embed via EmbeddingFunc)
}
Document is a data object in a Collection. Data fields are typed (string, float64, bool, []string) matching VS2 DataObject.
type EmbeddingFunc ¶
EmbeddingFunc converts text to an embedding vector. Same signature as chromem-go for drop-in compatibility.
type Filter ¶
Filter is a predicate over document data fields. Matches VS2's MongoDB-style filter operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $and, $or, $contains
func And ¶
And returns a filter that matches when ALL sub-filters match (short-circuits on first false).
func Contains ¶
Contains returns a filter that matches when the string field value contains the substring.
func Eq ¶
Eq returns a filter that matches when field == value. Supports string, float64, bool, and int types.
func NotContains ¶
NotContains returns a filter that matches when the string field value does NOT contain the substring.
type IndexConfig ¶
type IndexConfig struct {
FilterFields []string // fields to build inverted indexes on
Type IndexType // index algorithm: IndexIVF (default) or IndexHNSW
NumPartitions int // IVF: partitions (0 = auto √N)
NProbe int // IVF: partitions to search per query (0 = auto √NumPartitions)
SkipIVF bool // IVF: if true, only build filter indexes
M int // HNSW: max edges per layer (default 16)
EfConstruction int // HNSW: build-time beam width (default 200)
}
IndexConfig controls index creation (VS2-aligned).
type KVCacheConfig ¶
type KVCacheConfig struct {
Layers int // number of transformer layers
Heads int // number of attention heads
HeadDim int // dimension per head (typically 64 or 128)
Bits int // quantization bits per coordinate (default: 4)
PackIndices bool // bit-pack indices in storage (default: false)
Rotation RotationType // rotation algorithm (default: RotationHadamard)
Seed uint64 // rotation seed (default: 42)
}
KVCacheConfig controls KV cache creation.
type ModelConfig ¶
type ModelConfig struct {
Bits int // bits per coordinate (default: 4)
Rotation RotationType // rotation algorithm (default: RotationHadamard)
Seed uint64 // rotation seed (default: 42)
Workers int // concurrent workers per tensor (default: GOMAXPROCS)
}
ModelConfig controls model weight quantization.
type QueryOptions ¶
QueryOptions controls filter-only retrieval (VS2: QueryDataObjectsRequest).
type Result ¶
type Result struct {
ID string
Score float64 // inner product similarity (≈ cosine sim for unit-normalized vectors)
Content string
Data map[string]any
}
Result represents a search result from a Collection or Store.
type RotationType ¶
type RotationType int
RotationType selects the orthogonal rotation algorithm.
const ( // RotationQR uses a Haar-random orthogonal matrix via QR decomposition. // Memory: O(d²). Compute: O(d²) per vector. The paper's original approach. RotationQR RotationType = iota // RotationHadamard uses the Randomized Walsh-Hadamard Transform (D₂·H̃·D₁). // Memory: O(d). Compute: O(d log d) per vector. // Empirically better quality than QR (QuaRot, ICLR 2024). RotationHadamard )
type SafeTensorsFile ¶
type SafeTensorsFile struct {
// contains filtered or unexported fields
}
SafeTensorsFile provides read access to a SafeTensors (.safetensors) file. The file is memory-mapped for zero-copy access to tensor data.
func OpenSafeTensors ¶
func OpenSafeTensors(path string) (*SafeTensorsFile, error)
OpenSafeTensors opens a SafeTensors file for reading.
func (*SafeTensorsFile) Metadata ¶
func (sf *SafeTensorsFile) Metadata() map[string]string
Metadata returns the __metadata__ map (may be nil).
func (*SafeTensorsFile) NumTensors ¶
func (sf *SafeTensorsFile) NumTensors() int
NumTensors returns the total number of tensors.
func (*SafeTensorsFile) ReadRowFloat64 ¶
func (sf *SafeTensorsFile) ReadRowFloat64(name string, row int) ([]float64, error)
ReadRowFloat64 reads a single row of a tensor as float64. For 2D tensors, row is the first-dimension index. Supports F32, F16, BF16 dtypes.
func (*SafeTensorsFile) Tensor ¶
func (sf *SafeTensorsFile) Tensor(name string) (TensorInfo, bool)
Tensor returns info about a named tensor.
func (*SafeTensorsFile) TensorBytes ¶
func (sf *SafeTensorsFile) TensorBytes(name string) ([]byte, error)
TensorBytes returns the raw bytes for a tensor.
func (*SafeTensorsFile) TensorNames ¶
func (sf *SafeTensorsFile) TensorNames() []string
TensorNames returns all tensor names, sorted alphabetically.
type SearchOptions ¶
type SearchOptions struct {
TopK int // max results (default: 10)
MinScore float64 // minimum similarity threshold (0 = no filter)
Offset int // skip first N results (pagination)
Filter Filter // data field filter
Rescore int // rescore top-N with exact dequantized distance (0 = disabled, recommended: 3×TopK)
Ef int // HNSW: search beam width (0 = auto, higher = better recall, slower)
}
SearchOptions controls vector similarity search (VS2: SearchDataObjectsRequest).
type StoreConfig ¶
type StoreConfig struct {
Dim int // embedding dimension (required)
Bits int // bits per coordinate: 1-8 (default: 4)
Rotation RotationType // rotation algorithm (default: RotationQR)
Seed uint64 // rotation matrix seed (default: 42)
UseExactPDF bool // use exact Beta PDF for codebook
}
StoreConfig controls store creation.
func (StoreConfig) ToConfig ¶
func (c StoreConfig) ToConfig() Config
ToConfig converts StoreConfig to a quantizer Config.
func (StoreConfig) WithDefaults ¶
func (c StoreConfig) WithDefaults() StoreConfig
WithDefaults returns a copy with zero fields filled to defaults.
type StoreInfo ¶
type StoreInfo struct {
Path string
Dim int
WorkDim int
Bits int
Rotation RotationType
Seed uint64
NumVecs int
FileSize int64
IndexBytes int64
Compression float64 // ratio vs float32
}
StoreInfo contains statistics about a store.
type TQMTensorInfo ¶
type TQMTensorInfo struct {
Shape []int64 `json:"shape"`
OrigDType string `json:"orig_dtype"`
Rows int `json:"rows"`
RowDim int `json:"row_dim"`
WorkDim int `json:"work_dim"`
Offset int64 `json:"offset"`
Size int64 `json:"size"`
AvgCosSim float64 `json:"avg_cos_sim"`
}
TQMTensorInfo describes a quantized tensor in a .tqm file.
type TQModelHeader ¶
type TQModelHeader struct {
Version int `json:"version"`
Source string `json:"source,omitempty"`
Bits int `json:"bits"`
Packed bool `json:"packed"`
Rotation string `json:"rotation"`
Seed uint64 `json:"seed"`
Tensors map[string]TQMTensorInfo `json:"tensors"`
}
TQModelHeader is the JSON header of a .tqm file.
type TensorInfo ¶
type TensorInfo struct {
Name string
DType string `json:"dtype"`
Shape []int64 `json:"shape"`
DataOffsets [2]int64 `json:"data_offsets"`
}
TensorInfo describes a single tensor in a SafeTensors file.
func (TensorInfo) BytesPerElement ¶
func (ti TensorInfo) BytesPerElement() int
BytesPerElement returns the size of one element for the tensor's dtype.
func (TensorInfo) Cols ¶
func (ti TensorInfo) Cols() int
Cols returns the row dimension (last dimension) for a tensor.
func (TensorInfo) NumElements ¶
func (ti TensorInfo) NumElements() int64
NumElements returns the total number of elements in a tensor.
func (TensorInfo) Rows ¶
func (ti TensorInfo) Rows() int
Rows returns the number of rows (first dimension) for a 2D tensor. Returns 1 for 1D tensors, 0 for empty tensors.
Directories
¶
| Path | Synopsis |
|---|---|
|
bench
|
|
|
cmd/tqdb-annbench
command
tqdb-annbench: Standard ANN benchmark harness.
|
tqdb-annbench: Standard ANN benchmark harness. |
|
cmd
|
|
|
tqdb
command
|
|
|
tqdb-bench
command
tqdb-bench: Comprehensive comparison benchmark between chromem-go (float32) and tqdb (4-bit quantized) search quality and performance.
|
tqdb-bench: Comprehensive comparison benchmark between chromem-go (float32) and tqdb (4-bit quantized) search quality and performance. |
|
tqdb-debug-recall
command
tqdb-debug-recall: Diagnose why recall@10 doesn't match paper expectations.
|
tqdb-debug-recall: Diagnose why recall@10 doesn't match paper expectations. |
|
tqdb-prod-bench
command
tqdb-prod-bench: Compare MSE-only vs Prod (MSE+QJL) recall and latency.
|
tqdb-prod-bench: Compare MSE-only vs Prod (MSE+QJL) recall and latency. |
|
tqdb-recall
command
tqdb-recall: Measure recall vs latency tradeoffs for IVF tuning.
|
tqdb-recall: Measure recall vs latency tradeoffs for IVF tuning. |
|
tqdb-test
command
tqdb-test: End-to-end integration test + benchmark against live chromem-go data.
|
tqdb-test: End-to-end integration test + benchmark against live chromem-go data. |
|
internal
|
|
|
distancer
Package distancer provides SIMD-accelerated distance functions.
|
Package distancer provides SIMD-accelerated distance functions. |
|
embed
Package embed provides lightweight embedding provider clients.
|
Package embed provides lightweight embedding provider clients. |