Skip to content

clients.jina #

jina

see https://jina.ai/

To get started



import freeflowuniverse.herolib.clients. jina

mut client:= jina.get()!

client...

example heroscript

!!jina.configure
    secret: '...'
    host: 'localhost'
    port: 8888

Constants #

const version = '0.0.0'

fn delete #

fn delete(args_ ArgsGet) !

fn embedding_type_from_string #

fn embedding_type_from_string(s string) !EmbeddingType

from_string converts string to EmbeddingType enum

fn exists #

fn exists(args_ ArgsGet) !bool

does the config exists?

fn get #

fn get(args_ ArgsGet) !&Jina

fn heroscript_dumps #

fn heroscript_dumps(obj Jina) !string

///////////NORMALLY NO NEED TO TOUCH

fn heroscript_loads #

fn heroscript_loads(heroscript string) !Jina

fn jina_model_from_string #

fn jina_model_from_string(s string) !JinaModel

from_string converts a string to a JinaModel enum, returning an error if the string is invalid

fn jina_rerank_model_from_string #

fn jina_rerank_model_from_string(s string) !JinaRerankModel

from_string converts a string to a JinaRerankModel enum, returning an error if the string is invalid

fn play #

fn play(args_ PlayArgs) !

fn set #

fn set(o Jina) !

register the config for the future

fn switch #

fn switch(name string)

switch instance to be used for jina

fn task_type_from_string #

fn task_type_from_string(s string) !TaskType

from_string converts string to TaskType enum

fn truncate_type_from_string #

fn truncate_type_from_string(s string) !TruncateType

from_string converts string to TruncateType enum

type SEmbeddingType #

type SEmbeddingType = EmbeddingObjType | []f64 | []string | []u8

SEmbeddingType is a sum type to handle different embedding formats

enum ClassificationTrainAccess #

enum ClassificationTrainAccess {
	public  // Classifier is publicly accessible
	private // Classifier is private (default)
}

ClassificationTrainAccess represents the accessibility of the classifier

enum EmbeddingType #

enum EmbeddingType {
	float   // "float"
	base64  // "base64"
	binary  // "binary"
	ubinary // "ubinary"
}

EmbeddingType represents the available embedding types

fn (EmbeddingType) to_string #

fn (t EmbeddingType) to_string() string

to_string converts EmbeddingType enum to its string representation

enum JinaModel #

enum JinaModel {
	jina_clip_v1
	jina_clip_v2
	jina_embeddings_v2_base_en
	jina_embeddings_v2_base_es
	jina_embeddings_v2_base_de
	jina_embeddings_v2_base_zh
	jina_embeddings_v2_base_code
	jina_embeddings_v3
}

JinaModel represents the available Jina models

fn (JinaModel) to_string #

fn (m JinaModel) to_string() string

to_string converts a JinaModel enum to its string representation as expected by the Jina API

enum JinaRerankModel #

enum JinaRerankModel {
	reranker_v2_base_multilingual // 278M
	reranker_v1_base_en           // 137M
	reranker_v1_tiny_en           // 33M
	reranker_v1_turbo_en          // 38M
	colbert_v1_en                 // 137M
}

fn (JinaRerankModel) to_string #

fn (m JinaRerankModel) to_string() string

to_string converts a JinaRerankModel enum to its string representation as expected by the Jina API

enum MultiVectorInputType #

enum MultiVectorInputType {
	document // document
	query    // query
}

Enum for input types

enum MultiVectorModel #

enum MultiVectorModel {
	jina_colbert_v1_en // jina-colbert-v1-en
}

Enum for available Jina multi-vector models

fn (MultiVectorModel) to_string #

fn (m MultiVectorModel) to_string() string

Convert the enum to a valid string

enum TaskType #

enum TaskType {
	retrieval_query   // "retrieval.query"
	retrieval_passage // "retrieval.passage"
	text_matching     // "text-matching"
	classification    // "classification"
	separation        // "separation"
}

TaskType represents the available task types for embeddings

fn (TaskType) to_string #

fn (t TaskType) to_string() string

to_string converts TaskType enum to its string representation

enum TruncateType #

enum TruncateType {
	none_ // "NONE"
	start // "START"
	end   // "END"
}

TruncateType represents the available truncation options

fn (TruncateType) to_string #

fn (t TruncateType) to_string() string

to_string converts TruncateType enum to its string representation

struct ArgsGet #

@[params]
struct ArgsGet {
pub mut:
	name string
}

///////FACTORY

struct ClassificationInput #

struct ClassificationInput {
pub mut:
	text  ?string // Optional text content
	image ?string // Optional image content
}

ClassificationInput represents a single input for classification (text or image)

struct ClassificationOutput #

struct ClassificationOutput {
pub mut:
	data  []ClassificationResult // List of classification results
	usage ClassificationUsage    // Token usage details
}

ClassificationOutput represents the response from the classify endpoint

struct ClassificationResult #

struct ClassificationResult {
pub mut:
	index       int          // Index of the input
	prediction  string       // Predicted label
	score       f64          // Confidence score
	object      string       // Type of object (e.g., "classification")
	predictions []LabelScore // List of label scores
}

ClassificationResult represents a single classification result

struct ClassificationTrain #

@[params]
struct ClassificationTrain {
pub mut:
	model         ?JinaModel // Optional model identifier (e.g., jina-clip-v1)
	classifier_id ?string    // Optional existing classifier ID
	access        ?ClassificationTrainAccess = .private // Accessibility, defaults to private
	input         []TrainingExample // Array of training examples
	num_iters     ?int = 10 // Number of training iterations, defaults to 10
}

ClassificationTrain represents parameters for the training request

struct ClassificationTrainOutput #

struct ClassificationTrainOutput {
pub mut:
	classifier_id string                   // Identifier of the trained classifier
	num_samples   int                      // Number of samples used in training
	usage         ClassificationTrainUsage // Token usage details
}

ClassificationTrainOutput represents the response from the training endpoint

struct ClassificationTrainUsage #

struct ClassificationTrainUsage {
pub mut:
	total_tokens int // Total tokens consumed
}

ClassificationTrainUsage represents token usage for the training request

struct ClassificationUsage #

struct ClassificationUsage {
pub mut:
	total_tokens int // Total tokens consumed
}

ClassificationUsage represents token usage for the classification request

struct Classifier #

struct Classifier {
pub mut:
	classifier_id  string
	model_name     string
	labels         []string
	access         string
	updated_number int
	used_number    int
	created_at     string
	updated_at     string
	used_at        ?string
	metadata       map[string]string
}

Define the Classifier struct

struct ClassifyParams #

@[params]
struct ClassifyParams {
pub mut:
	model         ?JinaModel            // Optional model identifier
	classifier_id ?string               // Optional classifier ID
	input         []ClassificationInput // Array of inputs (text or image)
	labels        []string              // List of labels for classification
}

ClassifyParams represents parameters for the classification request

struct CreateEmbeddingParams #

@[params]
struct CreateEmbeddingParams {
pub mut:
	input         []string  @[required] // Input texts
	model         JinaModel @[required] // Model name
	task          string    @[required] // Task type
	type_         ?EmbeddingType // embedding type
	truncate      ?TruncateType  // truncation type
	late_chunking ?bool          // Flag to determine if late chunking is applied
}

CreateEmbeddingParams represents the parameters for creating embeddings

struct DefaultConfigArgs #

@[params]
struct DefaultConfigArgs {
	instance string = 'default'
}

helpers

struct DeleteClassifierParams #

@[params]
struct DeleteClassifierParams {
pub mut:
	classifier_id string @[required] // The ID of the classifier to delete
}

ClassifyParams represents parameters for the classification request

struct Embedding #

struct Embedding {
	index      int            // Index of the document
	embeddings SEmbeddingType // Embedding vector as a sum type
	object     string         // Object type as string
}

Embedding represents an embedding vector

struct EmbeddingData #

struct EmbeddingData {
pub mut:
	embedding []f64
	index     int
	object    string
}

EmbeddingData represents a single embedding result

struct EmbeddingObjType #

struct EmbeddingObjType {
pub mut:
	float  ?[][]f64  // Optional 2D array of floats for multi-vector embeddings
	base64 ?[]string // Optional array of base64 strings
	binary ?[]u8     // Optional array of bytes
}

EmbeddingObjType represents the embeddings object in the response

struct HealthResponse #

struct HealthResponse {
pub mut:
	status  string
	message string
	healthy bool
}

struct ImageDoc #

struct ImageDoc {
pub mut:
	image string // The image URL or base64-encoded string
}

ImageDoc represents an image document for classification

struct Jina #

@[heap]
struct Jina {
pub mut:
	name     string = 'default'
	secret   string
	base_url string = api_base_url
	// http     httpconnection.HTTPConnection @[str: skip]
}

THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED

fn (Jina) classify #

fn (mut j Jina) classify(params ClassifyParams) !ClassificationOutput

Classify inputs by sending a POST request to /v1/classify

fn (Jina) create_embeddings #

fn (mut j Jina) create_embeddings(params CreateEmbeddingParams) !ModelEmbeddingOutput

Create embeddings for input texts

fn (Jina) create_multi_vector #

fn (mut j Jina) create_multi_vector(params MultiVectorParams) !MultiVectorResponse

CreateMultiVector creates a multi-vector request and returns the response

fn (Jina) delete_classifier #

fn (mut j Jina) delete_classifier(params DeleteClassifierParams) !string

Function to delete a classifier by its ID

fn (Jina) health #

fn (mut j Jina) health() !HealthResponse

fn (Jina) list_classifiers #

fn (mut j Jina) list_classifiers() ![]Classifier

Implement the list_classifiers function

fn (Jina) rerank #

fn (mut j Jina) rerank(params RerankParams) !RankingOutput

Rerank documents based on a query

fn (Jina) train #

fn (mut j Jina) train(params ClassificationTrain) !ClassificationTrainOutput

Train a classifier by sending a POST request to /v1/train

struct LabelScore #

struct LabelScore {
pub mut:
	label string // Label name
	score f64    // Confidence score
}

LabelScore represents a label and its corresponding score

struct ModelEmbeddingOutput #

struct ModelEmbeddingOutput {
pub mut:
	model     string
	data      []EmbeddingData
	usage     Usage
	object    string
	dimension int
}

ModelEmbeddingOutput represents the response from embedding requests

struct MultiVectorParams #

@[params]
struct MultiVectorParams {
pub mut:
	model          MultiVectorModel = .jina_colbert_v1_en // Model name
	input          []MultiVectorTextDoc  // Input documents
	input_type     ?MultiVectorInputType // Optional: Type of the embedding to compute, query or document
	embedding_type ?[]string             // Optional: Embedding type
	dimensions     ?int                  // Optional: Number of dimensions
}

MultiVectorParams represents the parameters for a multi-vector request

struct MultiVectorResponse #

struct MultiVectorResponse {
	data   []Embedding // List of embeddings
	usage  Usage       // Usage information
	model  string      // Model name
	object string      // Object type as string
}

MultiVectorResponse represents the JSON response body for the /v1/multi-vector endpoint

struct MultiVectorTextDoc #

struct MultiVectorTextDoc {
pub mut:
	id         ?string // Optional: ID of the document
	text       string @[required] // Text of the document
	input_type ?MultiVectorInputType // Optional: Type of the embedding to compute, query or document
}

MultiVectorTextDoc represents a text document for a multi-vector request

struct PlayArgs #

@[params]
struct PlayArgs {
pub mut:
	heroscript string // if filled in then plbook will be made out of it
	plbook     ?playbook.PlayBook
	reset      bool
}

struct RankDocument #

struct RankDocument {
pub mut:
	text string
}

RankDocument represents a single document for reranking

struct RankResult #

struct RankResult {
pub mut:
	document        RankDocument
	index           int
	relevance_score f64
}

RankResult represents a single reranking result

struct RankingOutput #

struct RankingOutput {
pub mut:
	model   string
	results []RankResult
	usage   Usage
	object  string
}

RankingOutput represents the response from reranking requests

struct RerankInput #

struct RerankInput {
pub mut:
	model            string   @[required] // Model name
	query            string   @[required] // Query text
	documents        []string @[required] // Document texts
	top_n            ?int  // Optional: Number of top results to return
	return_documents ?bool // Optional: Flag to determine if the documents should be returned
}

RankAPIInput represents the input for reranking requests

struct RerankParams #

@[params]
struct RerankParams {
pub mut:
	model            JinaRerankModel @[required]
	query            string          @[required]
	documents        []string        @[required]
	top_n            ?int  // Optional: Number of top results to return
	return_documents ?bool // Optional: Flag to determine if the documents should be returned
}

struct TextDoc #

struct TextDoc {
pub mut:
	text string // The text content
}

TextDoc represents a text document for classification

struct TextEmbeddingInput #

struct TextEmbeddingInput {
pub mut:
	model         string = 'jina-embeddings-v2-base-en'
	input         []string @[required]
	task          TaskType       // task type
	type_         ?EmbeddingType // embedding type
	truncate      ?TruncateType  // truncation type
	late_chunking ?bool          // Flag to determine if late chunking is applied
}

TextEmbeddingInput represents the input for text embedding requests with enum types

struct TrainingExample #

struct TrainingExample {
pub mut:
	text  ?string // Optional text content
	image ?string // Optional image URL
	label string  // Required label
}

TrainingExample represents a single training example (either text or image with a label)

struct Usage #

struct Usage {
pub mut:
	total_tokens int
	unit         string
}

Usage represents token usage information