ragkit

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: MIT Imports: 5 Imported by: 0

README

ragkit is a Go package to help index and retrieve documents for a RAG server

ragkit_logo

Install:

go get github.com/suapapa/go_ragkit

Usage:

import ragkit "github.com/suapapa/go_ragkit"

Examples:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateID

func GenerateID(text string) string

GenerateID: Generate a unique ID for a document

func ToJSONStr

func ToJSONStr(v any) string

Types

type Document

type Document struct {
	ID       string         // Unique ID
	Text     string         // Original text
	Metadata map[string]any // Optional: Additional metadata
	Vector   []float32      // Optional: Embedding vector (generated by Embeder if not provided)
}

Document is a type that represents a document

func MakeDocsFromTexts

func MakeDocsFromTexts(texts []string, metadata map[string]any) []Document

type Embedder

type Embedder interface {
	// Embed: Convert texts to embedding vectors
	Embed(ctx context.Context, texts ...string) ([][]float32, error)
}

Embedder is a type that can embed texts into vectors

type Indexer

type Indexer interface {
	// Index: Index multiple documents
	// Returns: IDs of indexed documents
	Index(ctx context.Context, docs ...Document) ([]string, error)

	// Delete: Delete a document by ID
	Delete(ctx context.Context, id string) error

	// Exists: Check if a document with the given ID exists
	Exists(ctx context.Context, id string) (bool, error)
}

Indexer is a type that can index documents into a vector database

type RetrievedDoc

type RetrievedDoc struct {
	// ID       string         // Document ID
	// Score    float32        // Similarity score
	Vector   []float32      // Retrieved vector
	Text     string         // Retrieved text
	Metadata map[string]any // Optional metadata
}

RetrievedDoc is a type that represents a retrieved document from vector database

type Retriever

type Retriever interface {
	// Retrieve: Return top-K documents based on query vector
	Retrieve(ctx context.Context, query []float32, topK int) ([]RetrievedDoc, error)

	// RetrieveText: Return top-K documents based on text query
	RetrieveText(ctx context.Context, text string, topK int) ([]RetrievedDoc, error)
}

Retriever is a type that can retrieve documents from a vector database

type Vectorizer

type Vectorizer interface {
	Indexer
	Retriever
}

Vectorizer is a combination of Indexer and Retriever

Directories

Path Synopsis
embedder
examples
weaviate-ollama command
vectorizer

Jump to

Keyboard shortcuts

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