-
-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
embeddings: add example of proper usage, and tweak doc.go accordingly
For #379
- Loading branch information
Showing
2 changed files
with
37 additions
and
8 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
/* | ||
Package embeddings contains the implementation for creating vector | ||
embeddings from text using different APIs, like OpenAI and Google PaLM (VertexAI). | ||
Package embeddings contains helpers for creating vector embeddings from text | ||
using different providers. | ||
The main components of this package are: | ||
- Embedder interface: a common interface for creating vector embeddings from texts. | ||
- OpenAI: an Embedder implementation using the OpenAI API. | ||
- VertexAIPaLM: an Embedder implementation using Google PaLM (VertexAI) API. | ||
- Helper functions: utility functions for embedding, such as `batchTexts` and `maybeRemoveNewLines`. | ||
- [Embedder] interface: a common interface for creating vector embeddings | ||
from texts, with optional batching. | ||
- [NewEmbedder] creates implementations of [Embedder] from provider LLM | ||
(or Chat) clients. | ||
The package provides a flexible way to handle different APIs for generating | ||
embeddings by using the Embedder interface as an abstraction. | ||
See the package example below. | ||
*/ | ||
package embeddings |
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,30 @@ | ||
package embeddings_test | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/tmc/langchaingo/embeddings" | ||
"github.com/tmc/langchaingo/llms/openai" | ||
) | ||
|
||
func Example() { | ||
Check failure on line 11 in embeddings/example_test.go GitHub Actions / lint
|
||
llm, err := openai.New() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
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 | ||
} |