Documentation
¶
Overview ¶
Package search implements full-text search (BM25 via Bleve) and hybrid search (RRF merging) for the Cartograph knowledge graph.
Package search — vector.go provides brute-force vector similarity search and hybrid BM25+vector search via RRF fusion.
Index ¶
- Constants
- Variables
- func CleanQuery(raw string) string
- func CosineSimilarity(a, b []float32) float64
- func DeleteIndex(path string) error
- type Index
- type IndexDoc
- type RRFResult
- type RankedList
- type RegexBuildFile
- type RegexBuildStats
- type RegexIndex
- type RegexMatch
- type RegexSearchOptions
- type RegexSearchResult
- type SearchResult
- type VectorEntry
- type VectorResult
Constants ¶
const ( RegexIndexVersion = "codesearch-v1" RegexIndexFile = "index" RegexStatusIndexed = "indexed" RegexStatusDegraded = "degraded" DefaultRegexSearchLimit = 20 MaxRegexSearchLimit = 200 DefaultRegexContextLines = 1 MaxRegexContextLines = 5 MaxRegexFallbackFiles = 5000 MaxRegexFallbackBytes = int64(256 * 1024 * 1024) MaxRegexReturnedLineBytes = 2000 )
Variables ¶
var ErrRegexIndexMissing = errors.New("regex index missing")
Functions ¶
func CleanQuery ¶
CleanQuery normalises a raw query string for code search: lowercases, expands camelCase, splits on punctuation, strips stop words.
func CosineSimilarity ¶
CosineSimilarity computes the cosine similarity between two vectors. Returns 0 if either vector is zero-length or they have different dimensions.
func DeleteIndex ¶
DeleteIndex removes the index directory from disk.
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index wraps a Bleve index for searching graph nodes.
func NewMemoryIndex ¶
NewMemoryIndex creates an in-memory Bleve index (useful for testing).
func NewReadOnlyIndex ¶
NewReadOnlyIndex opens a persisted Bleve index in read-only mode. Uses a shared file lock so multiple processes can read concurrently.
func (*Index) IndexGraph ¶
IndexGraph indexes all searchable nodes from the graph. Returns the number of documents indexed.
func (*Index) Search ¶
func (ix *Index) Search(query string, limit int) ([]SearchResult, error)
Search performs a BM25 search over the index. Returns results sorted by descending score, limited to the given count.
func (*Index) SearchMulti ¶
func (ix *Index) SearchMulti(rawQuery string, limit int) ([]SearchResult, error)
SearchMulti performs multi-field, phrase-aware BM25 search with stop word removal and weighted RRF fusion across name and content fields. Name field gets 2× RRF weight. Returns results sorted by descending fused score.
type IndexDoc ¶
type IndexDoc struct {
ID string `json:"id"`
Name string `json:"name"`
Label string `json:"label"`
FilePath string `json:"filePath"`
Content string `json:"content,omitempty"`
Signature string `json:"signature,omitempty"`
Description string `json:"description,omitempty"`
Annotations string `json:"annotations,omitempty"`
}
IndexDoc is the document structure stored in the Bleve index.
type RRFResult ¶
RRFResult represents a fused search result with combined score.
func HybridSearch ¶
func HybridSearch(bm25Results []SearchResult, vectorResults []VectorResult, limit int, vectorWeight float64) []RRFResult
HybridSearch merges BM25 and vector results using Reciprocal Rank Fusion. vectorWeight controls vector influence relative to BM25 (default 1.0).
func RRFMerge ¶
func RRFMerge(resultSets ...[]SearchResult) []RRFResult
RRFMerge combines multiple ranked result lists using Reciprocal Rank Fusion (constant k=60) with equal weights. This is a convenience wrapper around WeightedRRFMerge.
func WeightedRRFMerge ¶
func WeightedRRFMerge(lists ...RankedList) []RRFResult
WeightedRRFMerge combines multiple weighted ranked result lists using Reciprocal Rank Fusion (k=60). Each list's rank contributions are multiplied by its weight.
type RankedList ¶
type RankedList struct {
Results []SearchResult
Weight float64
}
RankedList is a ranked result set with an associated weight for WeightedRRFMerge. A weight of 2.0 means each rank contribution from this list is doubled.
type RegexBuildFile ¶
type RegexBuildStats ¶
func BuildRegexIndex ¶
func BuildRegexIndex(dir string, files []RegexBuildFile) (RegexBuildStats, error)
BuildRegexIndex builds the regex search index from in-memory file contents and atomically publishes it under dir.
func BuildRegexIndexFromOpener ¶
func BuildRegexIndexFromOpener(dir string, paths []string, openFile func(string) (io.ReadCloser, error)) (RegexBuildStats, error)
BuildRegexIndexFromOpener builds the regex search index by reading each path through openFile and atomically publishes it under dir. Each reader is closed before the next path is opened.
type RegexIndex ¶
type RegexIndex struct {
// contains filtered or unexported fields
}
func OpenRegexIndex ¶
func OpenRegexIndex(dir string) (*RegexIndex, error)
func (*RegexIndex) Search ¶
func (ix *RegexIndex) Search(opts RegexSearchOptions) (RegexSearchResult, error)
type RegexMatch ¶
type RegexSearchOptions ¶
type RegexSearchResult ¶
type SearchResult ¶
SearchResult is a single result from a BM25 search.
type VectorEntry ¶
VectorEntry is a node ID + vector pair used as input to VectorSearch.
type VectorResult ¶
VectorResult is a single result from a vector similarity search.
func VectorSearch ¶
func VectorSearch(query []float32, entries []VectorEntry, topK int, minScore float64) []VectorResult
VectorSearch performs brute-force cosine similarity search over a slice of entries. Returns the top-k results sorted by descending similarity, filtered to only include results above minScore.