diff --git a/.changeset/media-time-ranges.md b/.changeset/media-time-ranges.md new file mode 100644 index 0000000..7bace19 --- /dev/null +++ b/.changeset/media-time-ranges.md @@ -0,0 +1,5 @@ +--- +'@ontos-ai/knowhere-sdk': minor +--- + +Type audio/video time-range citations: `TimeRange` and optional `timeRanges` on retrieval sources and referenced chunks, plus transcript chunk metadata (`timeRanges`, `speakers`, `media`, `sourceKind`). diff --git a/README.md b/README.md index 5e59c8a..1ac24b5 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,7 @@ result.metadata; result.source.documentId; result.source.sourceFileName; result.source.sectionPath; +result.source.timeRanges; // audio/video only: [{ startMs, endMs }] ``` Agentic references expose the current retrieval citation fields: @@ -361,9 +362,13 @@ reference.sectionPath; reference.filePath; reference.jobId; reference.assetUrl; +reference.timeRanges; // audio/video only: [{ startMs, endMs }] reference.metadata; ``` +Audio and video documents are speech transcripts; their citations carry +`timeRanges` in milliseconds so you can seek the recording. + Use `documentId` to update or archive a document: ```typescript diff --git a/src/index.ts b/src/index.ts index c14c59f..cdefaac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,6 +49,7 @@ export type { RetrievalSectionExclusion, RetrievalQueryParams, RetrievalSource, + TimeRange, RetrievalEvidencePart, RetrievalResult, RetrievalReferencedChunk, diff --git a/src/lib/__tests__/utils.test.ts b/src/lib/__tests__/utils.test.ts index 9f0259c..280fb60 100644 --- a/src/lib/__tests__/utils.test.ts +++ b/src/lib/__tests__/utils.test.ts @@ -40,6 +40,25 @@ describe('utils', () => { }); describe('keysToCamel', () => { + it('should keep audio/video time_ranges citations as timeRanges', () => { + const input = { + referenced_chunks: [ + { + chunk_id: 'chunk_1', + time_ranges: [{ start_ms: 723000, end_ms: 860000 }], + }, + ], + }; + expect(keysToCamel(input)).toEqual({ + referencedChunks: [ + { + chunkId: 'chunk_1', + timeRanges: [{ startMs: 723000, endMs: 860000 }], + }, + ], + }); + }); + it('should convert object keys from snake_case to camelCase', () => { const input = { first_name: 'John', diff --git a/src/types/result.ts b/src/types/result.ts index 0bd1d0a..5d1118a 100644 --- a/src/types/result.ts +++ b/src/types/result.ts @@ -1,3 +1,5 @@ +import type { TimeRange } from './retrieval.js'; + /** * Statistics about the parsed document */ @@ -155,6 +157,14 @@ export interface ChunkMetadata { originalName?: string; tableType?: string; documentTopSummary?: string; + /** Audio/video transcript time spans */ + timeRanges?: TimeRange[]; + /** Speaker labels in an audio/video transcript chunk, e.g. S1 */ + speakers?: string[]; + /** Audio/video source facts: kind (audio or video) and durationMs */ + media?: { kind?: string; durationMs?: number | null }; + /** How the chunk text was produced, e.g. asr */ + sourceKind?: string; /** Allow forward-compatible access to unknown fields. */ [key: string]: unknown; } diff --git a/src/types/retrieval.ts b/src/types/retrieval.ts index 98d8c69..e2393b2 100644 --- a/src/types/retrieval.ts +++ b/src/types/retrieval.ts @@ -72,6 +72,14 @@ export interface RetrievalQueryParams { llmConfig?: LlmConfig; } +/** + * Audio/video time span in milliseconds from the start of the recording. + */ +export interface TimeRange { + startMs: number; + endMs: number; +} + /** * Caller-facing source reference attached to a retrieval result. */ @@ -86,6 +94,8 @@ export interface RetrievalSource { pageNums?: number[]; /** Original ingestion revision, shared by its baseline and final snapshots. */ jobResultId?: string | null; + /** Audio/video transcript time spans */ + timeRanges?: TimeRange[] | null; } /** @@ -154,6 +164,8 @@ export interface RetrievalReferencedChunk { pageNums?: number[]; /** Presigned asset URL for media chunks when available */ assetUrl?: string | null; + /** Audio/video transcript time spans */ + timeRanges?: TimeRange[] | null; /** Chunk metadata returned by the API */ metadata?: Record; }