Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanning a Vector from SQLite Back to Go #171

Open
wjkoh opened this issue Jan 15, 2025 · 0 comments
Open

Scanning a Vector from SQLite Back to Go #171

wjkoh opened this issue Jan 15, 2025 · 0 comments

Comments

@wjkoh
Copy link

wjkoh commented Jan 15, 2025

I store []float32 data using sqlite_vec's SerializeFloat32 function and am wondering how I can retrieve it from SQLite into Go. I've been using vec_to_json and unmarshaling the JSON on the Go side as the following code, but I suspect there might be a better approach. Could you please advise?

	var embeddingJson string
	row := db.QueryRowContext(
		ctx,
		`SELECT vec_to_json(embedding) FROM documents WHERE document_id = ?`,
		id,
	)
	err := row.Scan(&embeddingJson)
	if err != nil {
		return nil, err
	}
	var embedding []float32
	err = json.Unmarshal([]byte(embeddingJson), &embedding)
	if err != nil {
		return nil, err
	}
	return embedding, nil
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

No branches or pull requests

1 participant