Skip to content

Commit

Permalink
Add vector index support to git show / noms show
Browse files Browse the repository at this point in the history
  • Loading branch information
nicktobey committed Nov 26, 2024
1 parent 00d6c1d commit f9de9fa
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions go/store/types/serial_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ func (sm SerialMessage) HumanReadableStringAtIndentationLevel(level int) string

_ = OutputProllyNodeBytes(ret, serial.Message(sm))

// deleting everything from a vector index turns it into a regular index?
level -= 1
printWithIndendationLevel(level, ret, "}")
return ret.String()
case serial.VectorIndexNodeFileID:
ret := &strings.Builder{}
printWithIndendationLevel(level, ret, "Vector Index {\n")
level++

_ = OutputVectorIndexNodeBytes(ret, serial.Message(sm))

level -= 1
printWithIndendationLevel(level, ret, "}")
return ret.String()
Expand Down Expand Up @@ -493,6 +504,66 @@ func OutputProllyNodeBytes(w io.Writer, msg serial.Message) error {
return nil
}

func OutputVectorIndexNodeBytes(w io.Writer, msg serial.Message) error {
fileId, keys, values, treeLevel, count, err := message.UnpackFields(msg)
if fileId != serial.VectorIndexNodeFileID {
return fmt.Errorf("unexpected file ID, expected %s, got %s", serial.VectorIndexNodeFileID, fileId)
}
if err != nil {
return err
}
isLeaf := treeLevel == 0

for i := 0; i < int(count); i++ {
k := keys.GetItem(i, msg)
kt := val.Tuple(k)

w.Write([]byte("\n { key: "))
// The first key of a vector index is always a vector, which right now is JSON and thus addressable.
// This may not always be true in the future.

for j := 0; j < kt.Count(); j++ {
if j == 0 {
ref := hash.New(kt.GetField(0))

w.Write([]byte(" #"))
w.Write([]byte(ref.String()))
continue
}
if j > 0 {
w.Write([]byte(", "))
}

w.Write([]byte(hex.EncodeToString(kt.GetField(j))))
}

if isLeaf {
v := values.GetItem(i, msg)
vt := val.Tuple(v)

w.Write([]byte(" value: "))
for j := 0; j < vt.Count(); j++ {
if j > 0 {
w.Write([]byte(", "))
}
field := vt.GetField(j)
w.Write([]byte(hex.EncodeToString(field)))
}

w.Write([]byte(" }"))
} else {
ref := hash.New(values.GetItem(i, msg))

w.Write([]byte(" ref: #"))
w.Write([]byte(ref.String()))
w.Write([]byte(" }"))
}
}

w.Write([]byte("\n"))
return nil
}

func (sm SerialMessage) Less(ctx context.Context, nbf *NomsBinFormat, other LesserValuable) (bool, error) {
if v2, ok := other.(SerialMessage); ok {
return bytes.Compare(sm, v2) == -1, nil
Expand Down

0 comments on commit f9de9fa

Please sign in to comment.