Masterminds / squirrel

Fluent SQL generation for golang
Other
7.01k stars 465 forks source link

Request: parse slice of floating-point to vector #366

Open kevin19930919 opened 1 year ago

kevin19930919 commented 1 year ago

I am using squirrel to build my sql command with postgres,. Since I starting to use pgvector extension, I need to generate sql command with vector like:

SELECT * FROM  embedding WHERE catrgory_id = 1 ORDER BY embedding <=> '[-0.014099856, 0.015509841,-0.024045289]' LIMIT 2;

since there need to have comma between floating points, i need to do things like:

       // embedding type : []float64
    strSlice := make([]string, len(embedding))
    for i, v := range embedding {
        strSlice[i] = fmt.Sprintf("%v", v)
    }

 // ....... some code 
        Suffix(fmt.Sprintf("<=> '[%s]' LIMIT 2", strings.Join(strSlice, ", "))).
        ToSql()

can we have a syntax like CosineDistence(embedding) to handle this kind of case?

kevin19930919 commented 1 year ago

Would love to contribute to this if needed~