query

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package query provides a unified search engine that combines full-text (Bleve), structured metadata (SQLite), and vector similarity search into a single interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache provides a simple in-memory cache

func NewCache

func NewCache(maxSize int, defaultTTL time.Duration) *Cache

NewCache creates a new cache

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all items from the cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes an item from the cache

func (*Cache) Get

func (c *Cache) Get(key string) interface{}

Get retrieves an item from the cache

func (*Cache) GetStats

func (c *Cache) GetStats() map[string]int

GetStats returns cache statistics

func (*Cache) Set

func (c *Cache) Set(key string, value interface{})

Set adds an item to the cache

func (*Cache) SetWithTTL

func (c *Cache) SetWithTTL(key string, value interface{}, ttl time.Duration)

SetWithTTL adds an item to the cache with a specific TTL

type CacheEntry

type CacheEntry struct {
	Value      interface{}
	Expiration time.Time
}

CacheEntry represents a cached item

type Facet

type Facet struct {
	Term  string `json:"term"`
	Count int    `json:"count"`
}

Facet represents a term and its count within a search facet aggregation.

type MetadataMatch

type MetadataMatch struct {
	ID     string                 `json:"id"`
	Type   string                 `json:"type"`
	Fields map[string]interface{} `json:"fields"`
}

MetadataMatch represents a result from structured metadata filtering (e.g., organism or library strategy).

type QueryEngine

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

QueryEngine provides a unified interface combining Bleve full-text search, SQLite metadata queries, and optional vector similarity search.

func NewQueryEngine

func NewQueryEngine(dataDir string) (*QueryEngine, error)

NewQueryEngine creates a new QueryEngine with database, Bleve, and optional vector search backends initialized from the given data directory.

func (*QueryEngine) Close

func (qe *QueryEngine) Close() error

Close releases all resources held by the query engine, including database connections, search indexes, vector store, and embedder.

func (*QueryEngine) FindSimilar

func (qe *QueryEngine) FindSimilar(entityType, accession string, limit int) ([]vectors.SimilarityResult, error)

FindSimilar finds studies or samples similar to the given accession using vector embeddings.

func (*QueryEngine) GetStats

func (qe *QueryEngine) GetStats() (map[string]interface{}, error)

GetStats returns statistics from all query engine subsystems including database counts, Bleve document counts, vector store stats, and cache metrics.

func (*QueryEngine) IndexDocument

func (qe *QueryEngine) IndexDocument(docType string, doc interface{}) error

IndexDocument indexes a document in Bleve and optionally generates and stores a vector embedding. The docType must be "study", "experiment", or "sample".

func (*QueryEngine) Search

func (qe *QueryEngine) Search(query string, opts SearchOptions) (*SearchResults, error)

Search performs a hybrid search across Bleve, SQLite metadata, and optionally vector similarity, merging and ranking results from all systems.

type SearchOptions

type SearchOptions struct {
	UseVectors      bool              `json:"use_vectors"`
	UseFuzzy        bool              `json:"use_fuzzy"`
	Filters         map[string]string `json:"filters"`
	Limit           int               `json:"limit"`
	IncludeFacets   bool              `json:"include_facets"`
	VectorThreshold float32           `json:"vector_threshold"`
}

SearchOptions configures search behavior including vector search, fuzzy matching, filters, and result limits.

type SearchResults

type SearchResults struct {
	TextMatches     []TextMatch                `json:"text_matches,omitempty"`
	MetadataMatches []MetadataMatch            `json:"metadata_matches,omitempty"`
	SimilarProjects []vectors.SimilarityResult `json:"similar_projects,omitempty"`
	Facets          map[string][]Facet         `json:"facets,omitempty"`
	TotalHits       int                        `json:"total_hits"`
	SearchTime      time.Duration              `json:"search_time"`
	Query           string                     `json:"query"`
}

SearchResults contains merged results from text, metadata, and vector search systems.

type TextMatch

type TextMatch struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type"`
	Score     float64                `json:"score"`
	Title     string                 `json:"title"`
	Highlight map[string][]string    `json:"highlight,omitempty"`
	Fields    map[string]interface{} `json:"fields"`
}

TextMatch represents a single full-text search hit with its relevance score and highlighted fragments.

Jump to

Keyboard shortcuts

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