txtai

package module
v0.0.0-...-9db6110 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

Go client for txtai

Version GitHub Release Date GitHub Issues GitHub Last Commit

txtai is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.

This repository contains Go bindings for the txtai API.

Installation

txtai.go can be installed as follows:

go get -u github.com/neuml/txtai.go

Alternatively, adding the following import within a module will also download txtai.go

import "github.com/neuml/txtai.go"

Examples

The examples directory has a series of examples that give an overview of txtai. See the list of examples below.

Example Description
Introducing txtai Overview of the functionality provided by txtai
Extractive QA with txtai Extractive question-answering with txtai
Labeling with zero-shot classification Labeling with zero-shot classification
Pipelines and workflows Pipelines and workflows

txtai.go connects to a txtai api instance. See this link for details on how to start a new api instance.

Once an api instance is running, do the following to run the examples.

git clone https://github.com/neuml/txtai.go
cd txtai.go/examples
make embeddings|extractor|labels|pipelines

Documentation

Overview

Base API definition

Embeddings definition

Extractor definition

Labels definition

Segmentation definition

Similarity definition

Summary definition

Textractor definition

Transcription definition

Translation definition

Workflow definition

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

Base API definition

func NewAPI

func NewAPI(params ...string) API

Creates a new API instance

func (*API) Get

func (api *API) Get(method string, params map[string]string, result interface{})

Executes a GET request. Loads response into result.

func (*API) Headers

func (api *API) Headers(request *resty.Request) *resty.Request

Adds headers

func (*API) Post

func (api *API) Post(method string, params interface{}, result interface{})

Executes a POST request. Loads response into result.

func (*API) Request

func (api *API) Request(method string, result interface{}) *resty.Request

Creates a new Resty request and returns it.

type Answer

type Answer struct {
	Name   string `json:"name"`
	Answer string `json:"answer"`
}

Answer response

type Document

type Document struct {
	Id   string `json:"id"`
	Text string `json:"text"`
}

Base input Document

type EmbeddingsAPI

type EmbeddingsAPI struct {
	// contains filtered or unexported fields
}

Embeddings definition

func Embeddings

func Embeddings(params ...string) EmbeddingsAPI

Creates an Embeddings instance.

func (*EmbeddingsAPI) Add

func (embeddings *EmbeddingsAPI) Add(documents interface{})

Adds a batch of documents for indexing.

func (*EmbeddingsAPI) BatchSearch

func (embeddings *EmbeddingsAPI) BatchSearch(queries []string, limit int, weights float64, index string) [][]SearchResult

Finds documents in the embeddings model most similar to the input queries.

func (*EmbeddingsAPI) BatchSimilarity

func (embeddings *EmbeddingsAPI) BatchSimilarity(queries []string, texts []string) [][]IndexResult

Computes the similarity between list of queries and list of text.

func (*EmbeddingsAPI) BatchTransform

func (embeddings *EmbeddingsAPI) BatchTransform(texts []string) [][]float64

Transforms list of text into embeddings array.

func (*EmbeddingsAPI) Count

func (embeddings *EmbeddingsAPI) Count() int

Total number of elements in this embeddings index.

func (*EmbeddingsAPI) Delete

func (embeddings *EmbeddingsAPI) Delete(ids []string) []string

Deletes from an embeddings index. Returns list of ids deleted.

func (*EmbeddingsAPI) Explain

func (embeddings *EmbeddingsAPI) Explain(query string, texts []string) []ExplainResult

func (*EmbeddingsAPI) Index

func (embeddings *EmbeddingsAPI) Index()

Builds an embeddings index for previously batched documents.

func (*EmbeddingsAPI) Reindex

func (embeddings *EmbeddingsAPI) Reindex(config interface{}, function string)

Reindex with new configuration

func (*EmbeddingsAPI) Search

func (embeddings *EmbeddingsAPI) Search(query string, limit int, weights float64, index string) []SearchResult

Finds documents in the embeddings model most similar to the input query.

func (*EmbeddingsAPI) Similarity

func (embeddings *EmbeddingsAPI) Similarity(query string, texts []string) []IndexResult

Computes the similarity between query and list of text.

func (*EmbeddingsAPI) Transform

func (embeddings *EmbeddingsAPI) Transform(text string) []float64

Transforms text into an embeddings array.

func (*EmbeddingsAPI) Upsert

func (embeddings *EmbeddingsAPI) Upsert()

Runs an embeddings upsert operation for previously batched documents.

type ExplainResult

type ExplainResult struct {
	Id     int     `json:"id"`
	Text   string  `json:"text"`
	Score  float64 `json:"score"`
	Tokens Tokens  `json:"tokens"`
}

type ExtractorAPI

type ExtractorAPI struct {
	// contains filtered or unexported fields
}

Extractor definition

func Extractor

func Extractor(params ...string) ExtractorAPI

Creates an Extractor instance.

func (*ExtractorAPI) Extract

func (extractor *ExtractorAPI) Extract(queue []Question, texts []string) []Answer

Extracts answers to input questions.

type IndexResult

type IndexResult struct {
	Id    int     `json:"id"`
	Score float64 `json:"score"`
}

Index result

type LabelsAPI

type LabelsAPI struct {
	// contains filtered or unexported fields
}

Labels definition

func Labels

func Labels(params ...string) LabelsAPI

Creates a Labels instance.

func (*LabelsAPI) BatchLabel

func (label *LabelsAPI) BatchLabel(texts []string, labels []string) []IndexResult

Applies a zero shot classifier to list of text using a list of labels.

func (*LabelsAPI) Label

func (label *LabelsAPI) Label(text string, labels []string) []IndexResult

Applies a zero shot classifier to a text using a list of labels.

type Question

type Question struct {
	Name     string `json:"name"`
	Query    string `json:"query"`
	Question string `json:"question"`
	Snippet  bool   `json:"snippet"`
}

Question parameters

type SearchResult

type SearchResult struct {
	Id    string  `json:"id"`
	Text  string  `json:"text"`
	Score float64 `json:"score"`
}

Search result

type SegmentationAPI

type SegmentationAPI struct {
	// contains filtered or unexported fields
}

Segmentation definition

func Segmentation

func Segmentation(params ...string) SegmentationAPI

Creates a Segmentation instance.

func (*SegmentationAPI) BatchSegment

func (segmentation *SegmentationAPI) BatchSegment(texts []string) []interface{}

Segments text into semantic units.

func (*SegmentationAPI) Segment

func (segmentation *SegmentationAPI) Segment(text string) interface{}

Segments text into semantic units.

type SimilarityAPI

type SimilarityAPI struct {
	// contains filtered or unexported fields
}

Similarity definition

func Similarity

func Similarity(params ...string) SimilarityAPI

Creates a Similarity instance.

func (*SimilarityAPI) BatchSimilarity

func (similarity *SimilarityAPI) BatchSimilarity(queries []string, texts []string) [][]IndexResult

Computes the similarity between list of queries and list of text.

func (*SimilarityAPI) Similarity

func (similarity *SimilarityAPI) Similarity(query string, texts []string) []IndexResult

Computes the similarity between query and list of text.

type SummaryAPI

type SummaryAPI struct {
	// contains filtered or unexported fields
}

Summary definition

func Summary

func Summary(params ...string) SummaryAPI

Creates a Summary instance.

func (*SummaryAPI) BatchSummary

func (summary *SummaryAPI) BatchSummary(texts []string, minlength int, maxlength int) []string

Runs a summarization model against a block of text.

func (*SummaryAPI) Summary

func (summary *SummaryAPI) Summary(text string, minlength int, maxlength int) string

Runs a summarization model against a block of text.

type TextractorAPI

type TextractorAPI struct {
	// contains filtered or unexported fields
}

Textractor definition

func Textractor

func Textractor(params ...string) TextractorAPI

Creates a Textractor instance.

func (*TextractorAPI) BatchTextract

func (textractor *TextractorAPI) BatchTextract(files []string) []interface{}

Extracts text from a file at path.

func (*TextractorAPI) Textract

func (textractor *TextractorAPI) Textract(file string) interface{}

Extracts text from a file at path.

type Tokens

type Tokens map[string]float64

func (*Tokens) UnmarshalJSON

func (t *Tokens) UnmarshalJSON(data []byte) error

type TranscriptionAPI

type TranscriptionAPI struct {
	// contains filtered or unexported fields
}

Transcription definition

func Transcription

func Transcription(params ...string) TranscriptionAPI

Creates a Transcription instance.

func (*TranscriptionAPI) BatchTranscribe

func (transcription *TranscriptionAPI) BatchTranscribe(files []string) []string

Transcribes audio files to text.

func (*TranscriptionAPI) Transcribe

func (transcription *TranscriptionAPI) Transcribe(file string) string

Transcribes audio files to text.

type TranslationAPI

type TranslationAPI struct {
	// contains filtered or unexported fields
}

Translation definition

func Translation

func Translation(params ...string) TranslationAPI

Creates a Translation instance.

func (*TranslationAPI) BatchTranslate

func (translation *TranslationAPI) BatchTranslate(texts []string, target string, source string) []string

Translates text from source language into target language.

func (*TranslationAPI) Translate

func (translation *TranslationAPI) Translate(text string, target string, source string) string

Translates text from source language into target language.

type WorkflowAPI

type WorkflowAPI struct {
	// contains filtered or unexported fields
}

Workflow definition

func Workflow

func Workflow(params ...string) WorkflowAPI

Creates a Workflow instance.

func (*WorkflowAPI) Workflow

func (workflow *WorkflowAPI) Workflow(name string, elements []string) []interface{}

Segments text into semantic units.

Directories

Path Synopsis
Example embeddings functionality.
Example embeddings functionality.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL