text2vec-jinaai
Overview
The text2vec-jinaai
module enables Weaviate to obtain vectors using JinaAI Embeddings.
Key notes:
- As it uses a third-party API, you will need an API key.
- Its usage may incur costs.
- JinaAI requires a third-party API key. You can obtain one here.
- When you enable the text2vec-jinaai model, you can use the nearText search operator.
- The default model is
jina-embeddings-v2-base-en
.
v1.22.3
Weaviate instance configuration
Docker Compose file
To use text2vec-jinaai
, you must enable it in your Docker Compose file (docker-compose.yml
). You can edit the Docker Compose file manually, or use the the Weaviate configuration tool to create a custom file.
Parameters
Parameter | Required | Purpose |
---|---|---|
ENABLE_MODULES | Yes | The modules to enable. Include text2vec-jinaai to enable the module. |
DEFAULT_VECTORIZER_MODULE | No | The default vectorizer module. To make text2vec-jinaai the default for all classes, set it here. |
JINAAI_APIKEY | No | Your JinaAI API key. You can also provide the key at query time. |
Example
This Docker Compose file shows how to use JinaAI as the vectorizer.
- It enables
text2vec-jinaai
. - It sets
text2vec-jinaai
as the default vectorizer. - It sets a JinaAI API key.
---
services:
weaviate:
image: cr.weaviate.io/semitechnologies/weaviate:1.26.4
restart: on-failure:0
ports:
- 8080:8080
- 50051:50051
environment:
QUERY_DEFAULTS_LIMIT: 20
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
PERSISTENCE_DATA_PATH: "./data"
ENABLE_MODULES: 'text2vec-jinaai'
DEFAULT_VECTORIZER_MODULE: 'text2vec-jinaai'
JINAAI_APIKEY: 'YOUR_JINAAI_API_KEY' # Setting this parameter is optional, you can also provide the key at query time.
CLUSTER_HOSTNAME: 'node1'
...
Collection configuration
To configure how the module behaves in each collection, update the Weaviate schema.
API settings
Parameters
Parameter | Required | Default | Purpose |
---|---|---|---|
model | No | jina-embeddings-v2-base-en | A model name, e.g. jina-embeddings-v2-small-en . |
Example
The following example configures the Document
collection by setting the vectorizer to text2vec-jinaai
and the model to jina-embeddings-v2-small-en
:
{
"classes": [
{
"class": "Document",
"description": "A collection called document",
"vectorizer": "text2vec-jinaai",
"moduleConfig": {
"text2vec-jinaai": {
"model": "jina-embeddings-v2-small-en",
}
},
}
]
}
Vectorization settings
You can set vectorizer behavior using the moduleConfig
section under each collection and property:
Collection level settings
Parameter | Type | Default | Purpose |
---|---|---|---|
vectorizer | string | - | Sets the module for vectorization. |
vectorizeClassName | boolean | true | Whether to include the class name during vectorization. |
Property level settings
Parameter | Type | Default | Purpose |
---|---|---|---|
skip | boolean | false | When true , does not include the property during vectorization. |
vectorizePropertyName | boolean | false | Whether to include the property name during vectorization. |
Example
{
"classes": [
{
"class": "Document",
"description": "A collection called document",
"vectorizer": "text2vec-jinaai",
"moduleConfig": {
"text2vec-jinaai": {
"model": "jina-embeddings-v2-small-en",
"vectorizeClassName": false
}
},
"properties": [
{
"name": "content",
"dataType": ["text"],
"description": "Content that will be vectorized",
"moduleConfig": {
"text2vec-jinaai": {
"skip": false,
"vectorizePropertyName": false
}
}
}
]
}
]
}
Query-time parameters
API key
You can supply the API key at query time by adding it to the HTTP header.
HTTP Header | Value | Purpose |
---|---|---|
X-Jinaai-Api-Key | YOUR-JINAAI-API-KEY | JinaAI API key |
Usage example
This is an example of a nearText
query that uses text2vec-jinaai
.
- Python Client v4
- Python Client v3
- JS/TS Client v2
- Go
- Java
- Curl
- GraphQL
import weaviate
from weaviate.classes.query import MetadataQuery, Move
import os
client = weaviate.connect_to_local(
headers={
"X-Jinaai-Api-Key": "YOUR_JINAAI_APIKEY",
}
)
publications = client.collections.get("Publication")
response = publications.query.near_text(
query="fashion",
distance=0.6,
move_to=Move(force=0.85, concepts="haute couture"),
move_away=Move(force=0.45, concepts="finance"),
return_metadata=MetadataQuery(distance=True),
limit=2
)
for o in response.objects:
print(o.properties)
print(o.metadata)
client.close()
import weaviate
client = weaviate.Client(
url="http://localhost:8080",
additional_headers={
"X-Jinaai-Api-Key": "YOUR-JINAAI-API-KEY"
}
)
nearText = {
"concepts": ["fashion"],
"distance": 0.6,
"moveAwayFrom": {
"concepts": ["finance"],
"force": 0.45
},
"moveTo": {
"concepts": ["haute couture"],
"force": 0.85
}
}
result = (
client.query
.get("Publication", "name")
.with_additional(["certainty OR distance"]) # note certainty is only supported
# if distance==cosine
.with_near_text(nearText)
.do()
)
print(result)
import weaviate from 'weaviate-ts-client';
const client = weaviate.client({
scheme: 'http',
host: 'localhost:8080',
headers: { 'X-Jinaai-Api-Key': process.env['YOUR_JINAAI_API_KEY'] },
});
const response = await client.graphql
.get()
.withClassName('Publication')
.withFields('name _additional { certainty distance }') // note that certainty is only supported if distance==cosine
.withNearText({
concepts: ['fashion'],
distance: 0.6,
moveAwayFrom: {
concepts: ['finance'],
force: 0.45,
},
moveTo: {
concepts: ['haute couture'],
force: 0.85,
},
})
.do();
console.log(response);
package main
import (
"context"
"fmt"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate-go-client/v4/weaviate/graphql"
)
func main() {
cfg := weaviate.Config{
Host: "localhost:8080",
Scheme: "http",
Headers: map[string]string{"X-Jinaai-Api-Key": "YOUR-JINAAI-API-KEY"},
}
client, err := weaviate.NewClient(cfg)
if err != nil {
panic(err)
}
className := "Publication"
name := graphql.Field{Name: "name"}
_additional := graphql.Field{
Name: "_additional", Fields: []graphql.Field{
{Name: "certainty"}, // only supported if distance==cosine
{Name: "distance"}, // always supported
},
}
concepts := []string{"fashion"}
distance := float32(0.6)
moveAwayFrom := &graphql.MoveParameters{
Concepts: []string{"finance"},
Force: 0.45,
}
moveTo := &graphql.MoveParameters{
Concepts: []string{"haute couture"},
Force: 0.85,
}
nearText := client.GraphQL().NearTextArgBuilder().
WithConcepts(concepts).
WithDistance(distance).
WithMoveTo(moveTo).
WithMoveAwayFrom(moveAwayFrom)
ctx := context.Background()
result, err := client.GraphQL().Get().
WithClassName(className).
WithFields(name, _additional).
WithNearText(nearText).
Do(ctx)
if err != nil {
panic(err)
}
fmt.Printf("%v", result)
}
package io.weaviate;
import io.weaviate.client.Config;
import io.weaviate.client.WeaviateClient;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.graphql.model.GraphQLResponse;
import io.weaviate.client.v1.graphql.query.argument.NearTextArgument;
import io.weaviate.client.v1.graphql.query.argument.NearTextMoveParameters;
import io.weaviate.client.v1.graphql.query.fields.Field;
import java.util.HashMap;
import java.util.Map;
public class App {
public static void main(String[] args) {
Map<String, String> headers = new HashMap<String, String>() { {
put("X-Jinaai-Api-Key", "YOUR-JINAAI-API-KEY");
} };
Config config = new Config("http", "localhost:8080", headers);
WeaviateClient client = new WeaviateClient(config);
NearTextMoveParameters moveTo = NearTextMoveParameters.builder()
.concepts(new String[]{ "haute couture" }).force(0.85f).build();
NearTextMoveParameters moveAway = NearTextMoveParameters.builder()
.concepts(new String[]{ "finance" }).force(0.45f)
.build();
NearTextArgument nearText = client.graphQL().arguments().nearTextArgBuilder()
.concepts(new String[]{ "fashion" })
.distance(0.6f)
.moveTo(moveTo)
.moveAwayFrom(moveAway)
.build();
Field name = Field.builder().name("name").build();
Field _additional = Field.builder()
.name("_additional")
.fields(new Field[]{
Field.builder().name("certainty").build(), // only supported if distance==cosine
Field.builder().name("distance").build(), // always supported
}).build();
Result<GraphQLResponse> result = client.graphQL().get()
.withClassName("Publication")
.withFields(name, _additional)
.withNearText(nearText)
.run();
if (result.hasErrors()) {
System.out.println(result.getError());
return;
}
System.out.println(result.getResult());
}
}
# Under _additional, `certainty` is only supported if distance==cosine,
# but `distance` is always supported
echo '{
"query": "{
Get{
Publication(
nearText: {
concepts: [\"fashion\"],
distance: 0.6,
moveAwayFrom: {
concepts: [\"finance\"],
force: 0.45
},
moveTo: {
concepts: [\"haute couture\"],
force: 0.85
}
}
){
name
_additional {
certainty
distance
}
}
}
}"
}' | curl \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer learn-weaviate' \
-H "X-Jinaai-Api-Key: $JINAAI_API_KEY" \
-d @- \
https://edu-demo.weaviate.network/v1/graphql
{
Get{
Publication(
nearText: {
concepts: ["fashion"],
distance: 0.6 # prior to v1.14 use "certainty" instead of "distance"
moveAwayFrom: {
concepts: ["finance"],
force: 0.45
},
moveTo: {
concepts: ["haute couture"],
force: 0.85
}
}
){
name
_additional {
certainty # only supported if distance==cosine.
distance # always supported
}
}
}
}
Additional information
Available models
The following models are available:
jina-embeddings-v2-base-en
(Default)jina-embeddings-v2-small-en
Questions and feedback
If you have any questions or feedback, let us know in the user forum.