rag

package
v0.0.4-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: EUPL-1.2 Imports: 15 Imported by: 0

Documentation

Overview

Package rag provides RAG (Retrieval Augmented Generation) functionality for storing and querying documentation in Qdrant vector database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Category

func Category(path string) string

Category determines the document category from file path.

func ChunkID

func ChunkID(path string, index int, text string) string

ChunkID generates a unique ID for a chunk.

func FileExtensions

func FileExtensions() []string

FileExtensions returns the file extensions to process.

func FormatResultsContext

func FormatResultsContext(results []QueryResult) string

FormatResultsContext formats query results for LLM context injection.

func FormatResultsJSON

func FormatResultsJSON(results []QueryResult) string

FormatResultsJSON formats query results as JSON-like output.

func FormatResultsText

func FormatResultsText(results []QueryResult) string

FormatResultsText formats query results as plain text.

func IngestFile

func IngestFile(ctx context.Context, qdrant *QdrantClient, ollama *OllamaClient, collection string, filePath string, chunkCfg ChunkConfig) (int, error)

IngestFile processes a single file and stores it in Qdrant.

func ShouldProcess

func ShouldProcess(path string) bool

ShouldProcess checks if a file should be processed based on extension.

Types

type Chunk

type Chunk struct {
	Text    string
	Section string
	Index   int
}

Chunk represents a text chunk with metadata.

func ChunkMarkdown

func ChunkMarkdown(text string, cfg ChunkConfig) []Chunk

ChunkMarkdown splits markdown text into chunks by sections and paragraphs. Preserves context with configurable overlap.

type ChunkConfig

type ChunkConfig struct {
	Size    int // Characters per chunk
	Overlap int // Overlap between chunks
}

ChunkConfig holds chunking configuration.

func DefaultChunkConfig

func DefaultChunkConfig() ChunkConfig

DefaultChunkConfig returns default chunking configuration.

type IngestConfig

type IngestConfig struct {
	Directory  string
	Collection string
	Recreate   bool
	Verbose    bool
	BatchSize  int
	Chunk      ChunkConfig
}

IngestConfig holds ingestion configuration.

func DefaultIngestConfig

func DefaultIngestConfig() IngestConfig

DefaultIngestConfig returns default ingestion configuration.

type IngestProgress

type IngestProgress func(file string, chunks int, total int)

IngestProgress is called during ingestion to report progress.

type IngestStats

type IngestStats struct {
	Files  int
	Chunks int
	Errors int
}

IngestStats holds statistics from ingestion.

func Ingest

func Ingest(ctx context.Context, qdrant *QdrantClient, ollama *OllamaClient, cfg IngestConfig, progress IngestProgress) (*IngestStats, error)

Ingest processes a directory of documents and stores them in Qdrant.

type OllamaClient

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

OllamaClient wraps the Ollama API client for embeddings.

func NewOllamaClient

func NewOllamaClient(cfg OllamaConfig) (*OllamaClient, error)

NewOllamaClient creates a new Ollama client.

func (*OllamaClient) Embed

func (o *OllamaClient) Embed(ctx context.Context, text string) ([]float32, error)

Embed generates embeddings for the given text.

func (*OllamaClient) EmbedBatch

func (o *OllamaClient) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

EmbedBatch generates embeddings for multiple texts.

func (*OllamaClient) EmbedDimension

func (o *OllamaClient) EmbedDimension() uint64

EmbedDimension returns the embedding dimension for the configured model. nomic-embed-text uses 768 dimensions.

func (*OllamaClient) Model

func (o *OllamaClient) Model() string

Model returns the configured embedding model name.

func (*OllamaClient) VerifyModel

func (o *OllamaClient) VerifyModel(ctx context.Context) error

VerifyModel checks if the embedding model is available.

type OllamaConfig

type OllamaConfig struct {
	Host  string
	Port  int
	Model string
}

OllamaConfig holds Ollama connection configuration.

func DefaultOllamaConfig

func DefaultOllamaConfig() OllamaConfig

DefaultOllamaConfig returns default Ollama configuration. Host defaults to localhost for local development.

type Point

type Point struct {
	ID      string
	Vector  []float32
	Payload map[string]any
}

Point represents a vector point with payload.

type QdrantClient

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

QdrantClient wraps the Qdrant Go client with convenience methods.

func NewQdrantClient

func NewQdrantClient(cfg QdrantConfig) (*QdrantClient, error)

NewQdrantClient creates a new Qdrant client.

func (*QdrantClient) Close

func (q *QdrantClient) Close() error

Close closes the Qdrant client connection.

func (*QdrantClient) CollectionExists

func (q *QdrantClient) CollectionExists(ctx context.Context, name string) (bool, error)

CollectionExists checks if a collection exists.

func (*QdrantClient) CollectionInfo

func (q *QdrantClient) CollectionInfo(ctx context.Context, name string) (*qdrant.CollectionInfo, error)

CollectionInfo returns information about a collection.

func (*QdrantClient) CreateCollection

func (q *QdrantClient) CreateCollection(ctx context.Context, name string, vectorSize uint64) error

CreateCollection creates a new collection with cosine distance.

func (*QdrantClient) DeleteCollection

func (q *QdrantClient) DeleteCollection(ctx context.Context, name string) error

DeleteCollection deletes a collection.

func (*QdrantClient) HealthCheck

func (q *QdrantClient) HealthCheck(ctx context.Context) error

HealthCheck verifies the connection to Qdrant.

func (*QdrantClient) ListCollections

func (q *QdrantClient) ListCollections(ctx context.Context) ([]string, error)

ListCollections returns all collection names.

func (*QdrantClient) Search

func (q *QdrantClient) Search(ctx context.Context, collection string, vector []float32, limit uint64, filter map[string]string) ([]SearchResult, error)

Search performs a vector similarity search.

func (*QdrantClient) UpsertPoints

func (q *QdrantClient) UpsertPoints(ctx context.Context, collection string, points []Point) error

UpsertPoints inserts or updates points in a collection.

type QdrantConfig

type QdrantConfig struct {
	Host   string
	Port   int
	APIKey string
	UseTLS bool
}

QdrantConfig holds Qdrant connection configuration.

func DefaultQdrantConfig

func DefaultQdrantConfig() QdrantConfig

DefaultQdrantConfig returns default Qdrant configuration. Host defaults to localhost for local development.

type QueryConfig

type QueryConfig struct {
	Collection string
	Limit      uint64
	Threshold  float32 // Minimum similarity score (0-1)
	Category   string  // Filter by category
}

QueryConfig holds query configuration.

func DefaultQueryConfig

func DefaultQueryConfig() QueryConfig

DefaultQueryConfig returns default query configuration.

type QueryResult

type QueryResult struct {
	Text       string
	Source     string
	Section    string
	Category   string
	ChunkIndex int
	Score      float32
}

QueryResult represents a query result with metadata.

func Query

func Query(ctx context.Context, qdrant *QdrantClient, ollama *OllamaClient, query string, cfg QueryConfig) ([]QueryResult, error)

Query searches for similar documents in Qdrant.

type SearchResult

type SearchResult struct {
	ID      string
	Score   float32
	Payload map[string]any
}

SearchResult represents a search result with score.

Jump to

Keyboard shortcuts

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