module Memo::Search

Overview

Semantic search operations

Extended Modules

Defined in:

memo/search.cr

Instance Method Summary

Instance Method Detail

def mark_as_read(db : DB::Database, chunk_ids : Array(Int64)) #

Mark chunks as read (increment read_count)


[View source]
def semantic(db : DB::Database, embedding : Array(Float64), service_id : Int64, limit : Int32 = 10, min_score : Float64 = 0.7, filters : Filters | Nil = nil, detail : Symbol = :reference, sql_where : String | Nil = nil, projection_vectors : Array(Array(Float64)) | Nil = nil, projection_threshold : Float64 = 2.0, like : Array(String) | Nil = nil, match : String | Nil = nil, include_text : Bool = true) : Array(Result) #

Semantic search by embedding

Returns results ranked by cosine similarity

IMPORTANT: Must provide service_id to ensure embeddings are from same vector space

sql_where: Raw SQL fragment to filter chunks. Example: "c.source_id IN (SELECT id FROM main.artifact WHERE memo_id = artifact.source_id)" Note: c.source_id is the internal ID (FK to sources table)

like: Array of LIKE patterns for AND filtering by text content. Requires text storage to be enabled.

match: FTS5 full-text search query (e.g., "cats OR dogs"). Requires text storage to be enabled.

include_text: If true, includes text content in search results. Requires text storage to be enabled.

projection_vectors: Random orthogonal vectors for fast pre-filtering. If provided, candidates are filtered by projection distance before computing full cosine similarity.

projection_threshold: Maximum squared distance in projection space. Candidates with projection distance > threshold are skipped. Default 2.0 is generous to avoid false negatives.


[View source]