mirror of
https://git.pumpin.online/funkpower/catena.git
synced 2026-10-23 11:17:13 +00:00
cueseg: chapter by vectors somebody else made, where there are some
The hashed bag of words asks only whether two stretches repeat the same words, and cannot tell that ships and vessels are one subject. An embedding can. segment_with takes one vector per window and falls back to the words when it is given none, or the wrong number of them — a caller that embedded some other recording's windows is asking about that recording. windows_of gives the text to embed, in the order the vectors come back in, so nobody has to reimplement the windowing pass to use this. Bound in all three languages, and on the command line as --windows and --embeddings, which pipe through emb. The C ABI version goes to 2: catena_segment_cues gained an argument.
This commit is contained in:
@@ -212,10 +212,31 @@ pub fn pack_cues(
|
||||
///
|
||||
/// `duration` is the recording's length in seconds; omit it and the last cue
|
||||
/// decides.
|
||||
/// `embeddings` is one vector per window, in the order `cueWindows` gives
|
||||
/// them; without it the windows are compared by the words they repeat.
|
||||
#[wasm_bindgen(js_name = segmentCues, skip_typescript)]
|
||||
pub fn segment_cues(cues: JsValue, duration: Option<f64>) -> Result<JsValue, JsValue> {
|
||||
pub fn segment_cues(
|
||||
cues: JsValue,
|
||||
duration: Option<f64>,
|
||||
embeddings: JsValue,
|
||||
) -> Result<JsValue, JsValue> {
|
||||
let cues: Vec<cuekit::Cue> = from_js(cues, "cues")?;
|
||||
to_js(&crate::segment_cues(&cues, duration.unwrap_or(0.0)))
|
||||
let vectors: Option<Vec<Vec<f64>>> = match embeddings.is_undefined() || embeddings.is_null() {
|
||||
true => None,
|
||||
false => Some(from_js(embeddings, "embeddings")?),
|
||||
};
|
||||
to_js(&crate::segment_cues_with(
|
||||
&cues,
|
||||
duration.unwrap_or(0.0),
|
||||
vectors.as_deref(),
|
||||
))
|
||||
}
|
||||
|
||||
/// The text of each window a transcript is measured in, to embed.
|
||||
#[wasm_bindgen(js_name = cueWindows, skip_typescript)]
|
||||
pub fn cue_windows(cues: JsValue) -> Result<JsValue, JsValue> {
|
||||
let cues: Vec<cuekit::Cue> = from_js(cues, "cues")?;
|
||||
to_js(&crate::cue_windows(&cues))
|
||||
}
|
||||
|
||||
/// Split a collection into the works inside it.
|
||||
@@ -288,7 +309,8 @@ const SIGNATURES: &'static str = r#"
|
||||
export function chunkMarkdown(markdown: string, target?: number, overlap?: number, min_tokens?: number, hard_max?: number): Chunk[];
|
||||
export function parseSubtitles(content: string, keep_repeats?: boolean): Cue[];
|
||||
export function packCues(cues: Cue[], seconds?: number, max_tokens?: number): Chunk[];
|
||||
export function segmentCues(cues: Cue[], duration?: number): Segment[];
|
||||
export function segmentCues(cues: Cue[], duration?: number, embeddings?: number[][]): Segment[];
|
||||
export function cueWindows(cues: Cue[]): string[];
|
||||
export function splitCollection(markdown: string): Section[];
|
||||
export function fuseHits(hits: Hit[], k?: number, weights?: Record<string, number>, limit?: number): Hit[];
|
||||
export function identify(name: string, data: Uint8Array): Doc;
|
||||
|
||||
Reference in New Issue
Block a user