mirror of
https://github.com/lfnovo/open-notebook.git
synced 2026-04-29 12:00:00 +00:00
Changes: - Move migrations/ under open_notebook/database/migrations/ - Extract AI models to open_notebook/ai/ (Model, ModelManager, provision) - Extract podcasts to open_notebook/podcasts/ (EpisodeProfile, SpeakerProfile, PodcastEpisode) - Reorganize prompts to mirror graphs structure (chat/, source_chat/) This improves code organization by: - Consolidating database concerns (migrations now with database code) - Separating AI infrastructure from domain entities - Isolating podcast feature into its own module - Creating consistent prompt/graph naming conventions All 52 tests pass.
66 lines
No EOL
2.3 KiB
Text
66 lines
No EOL
2.3 KiB
Text
|
|
REMOVE FUNCTION IF EXISTS fn::vector_search;
|
|
|
|
DEFINE FUNCTION IF NOT EXISTS fn::vector_search($query: array<float>, $match_count: int, $sources: bool, $show_notes: bool, $min_similarity: float) {
|
|
let $source_embedding_search =
|
|
IF $sources {(
|
|
SELECT
|
|
source.id as id,
|
|
source.title as title,
|
|
content,
|
|
source.id as parent_id,
|
|
vector::similarity::cosine(embedding, $query) as similarity
|
|
FROM source_embedding
|
|
WHERE embedding != none and array::len(embedding)=array::len($query) AND
|
|
vector::similarity::cosine(embedding, $query) >= $min_similarity
|
|
ORDER BY similarity DESC
|
|
LIMIT $match_count
|
|
)}
|
|
ELSE { [] };
|
|
|
|
let $source_insight_search =
|
|
IF $sources {(
|
|
SELECT
|
|
id,
|
|
insight_type + ' - ' + (source.title OR '') as title,
|
|
content,
|
|
source.id as parent_id,
|
|
vector::similarity::cosine(embedding, $query) as similarity
|
|
FROM source_insight
|
|
WHERE embedding != none and array::len(embedding)=array::len($query) AND
|
|
vector::similarity::cosine(embedding, $query) >= $min_similarity
|
|
ORDER BY similarity DESC
|
|
LIMIT $match_count
|
|
)}
|
|
ELSE { [] };
|
|
|
|
|
|
let $note_content_search =
|
|
IF $show_notes {(
|
|
SELECT
|
|
id,
|
|
title,
|
|
content,
|
|
id as parent_id,
|
|
vector::similarity::cosine(embedding, $query) as similarity
|
|
FROM note
|
|
WHERE embedding != none and array::len(embedding)=array::len($query) AND
|
|
vector::similarity::cosine(embedding, $query) >= $min_similarity
|
|
ORDER BY similarity DESC
|
|
LIMIT $match_count
|
|
)}
|
|
ELSE { [] };
|
|
|
|
|
|
let $all_results = array::union(
|
|
array::union($source_embedding_search, $source_insight_search),
|
|
$note_content_search
|
|
);
|
|
|
|
|
|
RETURN (select id, parent_id, title, math::max(similarity) as similarity,
|
|
array::flatten(content) as matches
|
|
from $all_results where id is not None
|
|
group by id, parent_id, title ORDER BY similarity DESC LIMIT $match_count);
|
|
|
|
}; |