Files
Eli Bendersky 357a3b5d3b embeddings: add example of proper usage, and tweak doc.go accordingly (#393)
* embeddings: add example of proper usage, and tweak doc.go accordingly

For #379

* Appease lint and add comment
2023-12-04 22:38:29 -08:00

32 lines
551 B
Go

package embeddings_test
import (
"context"
"log"
"github.com/tmc/langchaingo/embeddings"
"github.com/tmc/langchaingo/llms/openai"
)
func Example() { //nolint:testableexamples
llm, err := openai.New()
if err != nil {
log.Fatal(err)
}
// Create a new Embedder from the given LLM.
embedder, err := embeddings.NewEmbedder(llm)
if err != nil {
log.Fatal(err)
}
docs := []string{"doc 1", "another doc"}
embs, err := embedder.EmbedDocuments(context.Background(), docs)
if err != nil {
log.Fatal(err)
}
// Consume embs
_ = embs
}