Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/handlers/jsonl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"github.com/kevmo314/appendable/pkg/btree"
"github.com/kevmo314/appendable/pkg/hnsw"
"github.com/kevmo314/appendable/pkg/ngram"
"github.com/kevmo314/appendable/pkg/pointer"
"github.com/kevmo314/appendable/pkg/vectorpage"
"log/slog"
"math"
"strings"
Expand All @@ -16,6 +19,7 @@ import (
)

type JSONLHandler struct {
vectorPageManager *vectorpage.VectorPageManager
}

var _ appendable.DataHandler = (*JSONLHandler)(nil)
Expand Down Expand Up @@ -295,6 +299,24 @@ func (j JSONLHandler) handleJSONLObject(f *appendable.IndexFile, r []byte, dec *
}
}

case appendable.FieldTypeVector:
vector, ok := value.(hnsw.Point)
if !ok {
return fmt.Errorf("expected hnsw.Point")
}

if j.vectorPageManager == nil {
h := hnsw.NewHnsw(2, 10, 8, vector)
j.vectorPageManager = vectorpage.NewVectorPageManager(
page.BTree(&btree.BTree{Width: width}),
page.BPTree(&bptree.BPTree{Data: r, DataParser: j, Width: width}),
h)
} else {
if err := j.vectorPageManager.AddNode(vector); err != nil {
return fmt.Errorf("failed to add hnsw node: %w", err)
}
}

default:
return fmt.Errorf("unrecognized type: %T: %v", ft, ft)
}
Expand Down