Skip to content

Add bindings-backed Go SDK implementation#260

Open
anirudh-makuluri wants to merge 4 commits into
usemoss:mainfrom
anirudh-makuluri:go-sdk
Open

Add bindings-backed Go SDK implementation#260
anirudh-makuluri wants to merge 4 commits into
usemoss:mainfrom
anirudh-makuluri:go-sdk

Conversation

@anirudh-makuluri
Copy link
Copy Markdown
Contributor

@anirudh-makuluri anirudh-makuluri commented May 23, 2026

Pull Request Checklist

Please ensure that your PR meets the following requirements:

  • I have read the CONTRIBUTING guide.
  • I have updated the documentation (if applicable).
  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Description

This PR adds the first bindings-backed Go SDK implementation for Moss.

What’s included:

  • adds sdks/go/bindings as a low-level CGO wrapper over libmoss
  • wires sdks/go/sdk to use the bindings layer for index management, document operations, local load/unload, and local query

Scope of this PR:

  • this is intended to land the core Go implementation first
  • current in-repo usage works and has been validated locally
  • external distribution / install ergonomics are intentionally left for follow-up work
  • for now, usage still requires an external libmoss C SDK plus -tags libmoss

Validation:

  • cd sdks/go/bindings && go test ./...
  • cd sdks/go/sdk && go test ./...
  • local end-to-end validation of:
    • create
    • get index / get docs
    • load
    • query
    • add docs
    • delete docs
    • delete index

Fixes #227

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Open in Devin Review

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 7 additional findings in Devin Review.

Open in Devin Review

Comment thread sdks/go/bindings/libmoss.go Outdated
Comment on lines +437 to +443
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])
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Suggested change
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])
}
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Go Bindings for Moss

1 participant