-
-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
googleai: add embeddings to vertex (#546)
for #410
- Loading branch information
Showing
6 changed files
with
56 additions
and
14 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package vertex | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/tmc/langchaingo/llms/googleai/internal/palmclient" | ||
) | ||
|
||
// CreateEmbedding creates embeddings from texts. | ||
func (g *Vertex) CreateEmbedding(ctx context.Context, texts []string) ([][]float32, error) { | ||
embeddings, err := g.palmClient.CreateEmbedding(ctx, &palmclient.EmbeddingRequest{ | ||
Input: texts, | ||
}) | ||
if err != nil { | ||
return [][]float32{}, err | ||
} | ||
|
||
if len(embeddings) == 0 { | ||
return nil, errors.New("empty response") | ||
} | ||
if len(texts) != len(embeddings) { | ||
return embeddings, fmt.Errorf("returned %d embeddings for %d texts", len(embeddings), len(texts)) | ||
} | ||
|
||
return embeddings, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters