internal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BaseURL = "http://localhost:11434/api/embeddings"
	Model   = "nomic-embed-text"
	APIKey  = ""
)

Functions

func AddDocument

func AddDocument(ctx context.Context, db *sql.DB, path string) error

AddDocument adds a single document to the database

func AddDocuments

func AddDocuments(ctx context.Context, db *sql.DB, paths []string, maxWorkers int) []error

AddDocuments processes multiple documents in parallel

func CreateDB

func CreateDB(dbPath string) (*sql.DB, bool, error)

CreateDB creates or opens a SQLite database at the given path. Returns the database connection, a boolean indicating if it's a new database, and any error that occurred.

func CreateEmbedding

func CreateEmbedding(ctx context.Context, text string) ([]float32, error)

func FindGitDir

func FindGitDir(startPath string) (string, error)

validateLocalFile checks if a local file is valid for processing

func GetAllFilePaths

func GetAllFilePaths(db *sql.DB) ([]string, error)

func GetConfig

func GetConfig(db *sql.DB) (map[string]string, error)

func GetDatabaseStats

func GetDatabaseStats(db *sql.DB) (map[string]int, error)

func InitDatabase

func InitDatabase(db *sql.DB, embeddingSize int) error

InitDatabase initializes the database schema with the required tables

func IsRemoteURL

func IsRemoteURL(path string) bool

IsRemoteURL checks if the given path is a remote URL

func LoadGitignoreFromFile

func LoadGitignoreFromFile(path string) ([]gitignore.Pattern, error)

func LoadGitignorePatterns

func LoadGitignorePatterns(gitDir string) ([]gitignore.Pattern, error)

func RecreateDatabase

func RecreateDatabase(db *sql.DB, embeddingSize int) ([]string, error)

RecreateDatabase recreates the database from scratch with the current schema

func RemoveDocument

func RemoveDocument(db *sql.DB, id int) error

RemoveDocument removes a document by its ID

func SaveConfig

func SaveConfig(db *sql.DB, config map[string]string) error

SaveConfig saves configuration key-value pairs to the database

Types

type Config

type Config struct {
	EmbeddingBaseURL string `json:"embedding_base_url"`
	EmbeddingModel   string `json:"embedding_model"`
	APIKey           string `json:"api_key,omitempty"` // Added API key field
}

func LoadConfig

func LoadConfig() (*Config, error)

type Document

type Document struct {
	ID       int64
	Path     string
	Content  string
	Title    string
	IsRemote bool

	// Only used for search results
	Distance float64
}

Document represents a stored document

func FetchDocument

func FetchDocument(path string) (*Document, error)

FetchDocument retrieves content from either a local file or remote URL

func GetAllDocuments

func GetAllDocuments(db *sql.DB) ([]Document, error)

GetAllDocuments retrieves all documents from the database

func GetDocumentByID

func GetDocumentByID(db *sql.DB, id int) (*Document, error)

GetDocumentByID retrieves a single document by its ID

func SearchDocuments

func SearchDocuments(
	db *sql.DB,
	queryEmbedding []float32,
	limit int,
	threshold *float64,
) ([]Document, error)

type EmbeddingRequest

type EmbeddingRequest struct {
	Model string `json:"model"`
	Input string `json:"prompt"`
}

Jump to

Keyboard shortcuts

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