Add bindings-backed Go SDK implementation#260
Conversation
| embedding := make([]float32, int(item.embedding_dim)) | ||
| if item.embedding != nil && item.embedding_dim > 0 { | ||
| values := unsafe.Slice(item.embedding, int(item.embedding_dim)) | ||
| for j := range values { | ||
| embedding[j] = float32(values[j]) | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 convertDocuments returns non-nil empty embedding slice for documents without embeddings
convertDocuments unconditionally allocates embedding := make([]float32, int(item.embedding_dim)) at line 437, even when embedding_dim is 0 and embedding is nil. make([]float32, 0) produces a non-nil empty slice ([]float32{}), so every document returned from GetDocs without an embedding gets Embedding: []float32{} instead of Embedding: nil. This is inconsistent with the sibling convertMetadata function (libmoss.go:454-456) which correctly returns nil for empty metadata. Any downstream consumer that checks doc.Embedding == nil to detect the absence of embeddings will get a false positive.
| embedding := make([]float32, int(item.embedding_dim)) | |
| if item.embedding != nil && item.embedding_dim > 0 { | |
| values := unsafe.Slice(item.embedding, int(item.embedding_dim)) | |
| for j := range values { | |
| embedding[j] = float32(values[j]) | |
| } | |
| } | |
| var embedding []float32 | |
| if item.embedding != nil && item.embedding_dim > 0 { | |
| embedding = make([]float32, int(item.embedding_dim)) | |
| values := unsafe.Slice(item.embedding, int(item.embedding_dim)) | |
| for j := range values { | |
| embedding[j] = float32(values[j]) | |
| } | |
| } |
Was this helpful? React with 👍 or 👎 to provide feedback.
Pull Request Checklist
Please ensure that your PR meets the following requirements:
Description
This PR adds the first bindings-backed Go SDK implementation for Moss.
What’s included:
sdks/go/bindingsas a low-level CGO wrapper overlibmosssdks/go/sdkto use the bindings layer for index management, document operations, local load/unload, and local queryScope of this PR:
libmossC SDK plus-tags libmossValidation:
cd sdks/go/bindings && go test ./...cd sdks/go/sdk && go test ./...Fixes #227
Type of Change