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

feat(community): update embedding jina #7292

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions docs/core_docs/docs/integrations/text_embedding/jina.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ Here’s how to create an instance of `JinaEmbeddings`:
import { JinaEmbeddings } from "@langchain/community/embeddings/jina";

const embeddings = new JinaEmbeddings({
apiToken: "YOUR_API_TOKEN",
model: "jina-embeddings-v2-base-en", // Optional, defaults to "jina-embeddings-v2-base-en"
apiKey: "YOUR_API_TOKEN",
model: "jina-clip-v2", // Optional, defaults to "jina-clip-v2"
});
```

If the `apiToken` is not provided, it will be read from the `JINA_API_KEY` environment variable.
If the `apiKey` is not provided, it will be read from the `JINA_API_KEY` environment variable.

## Generating Embeddings

Expand All @@ -59,10 +59,18 @@ console.log(embedding);
To generate embeddings for multiple documents, use the `embedDocuments` method.

```typescript
import { localImageToBase64 } from "@langchain/community/embeddings/jina/util";
const documents = [
"Document 1 text...",
"Document 2 text...",
"Document 3 text...",
'hello',
{
text: 'hello',
},
{
image: 'https://i.ibb.co/nQNGqL0/beach1.jpg',
},
{
image: await localImageToBase64('beach1.jpg'),
},
];

const embeddingsArray = await embeddings.embedDocuments(documents);
Expand All @@ -87,17 +95,29 @@ Here’s a complete example of how to set up and use the `JinaEmbeddings` class:

```typescript
import { JinaEmbeddings } from "@langchain/community/embeddings/jina";
import { localImageToBase64 } from "@langchain/community/embeddings/jina/util";

const embeddings = new JinaEmbeddings({
apiToken: "YOUR_API_TOKEN",
apiKey: "YOUR_API_TOKEN",
model: "jina-embeddings-v2-base-en",
});

async function runExample() {
const queryEmbedding = await embeddings.embedQuery("Example query text.");
console.log("Query Embedding:", queryEmbedding);

const documents = ["Text 1", "Text 2", "Text 3"];
const documents = [
'hello',
{
text: 'hello',
},
{
image: 'https://i.ibb.co/nQNGqL0/beach1.jpg',
},
{
image: await localImageToBase64('beach1.jpg'),
},
];
const documentEmbeddings = await embeddings.embedDocuments(documents);
console.log("Document Embeddings:", documentEmbeddings);
}
Expand Down
162 changes: 0 additions & 162 deletions libs/langchain-community/src/embeddings/jina.ts

This file was deleted.

Loading