Loading...
Skip to main content

Module: batteries/docs

This module provides the DocsQA component for document question and answering using an LLM. See: https://docs.ai-jsx.com/guides/brand-new#accessing-knowledge-docs-qa

Enumerations

Classes

Interfaces

Type Aliases

Chunker

Ƭ Chunker<DocumentMetadata, ChunkMetadata>: (document: Document<DocumentMetadata>) => Promise<Chunk<ChunkMetadata>[]>

Type parameters

NameType
DocumentMetadataextends Jsonifiable = Jsonifiable
ChunkMetadataextends Jsonifiable = Jsonifiable

Type declaration

▸ (document): Promise<Chunk<ChunkMetadata>[]>

A function that splits a document into multiple chunks, for example to ensure it fits in appropriate context windows.

Parameters
NameType
documentDocument<DocumentMetadata>
Returns

Promise<Chunk<ChunkMetadata>[]>

Defined in

ai-jsx/src/batteries/docs.tsx:261


Loader

Ƭ Loader<DocumentMetadata>: (request: CorpusLoadRequest) => Promise<CorpusLoadResponse<Document<DocumentMetadata>>>

Type parameters

NameType
DocumentMetadataextends Jsonifiable = Jsonifiable

Type declaration

▸ (request): Promise<CorpusLoadResponse<Document<DocumentMetadata>>>

A function responsible for loading and parsing a corpus.

Parameters
NameType
requestCorpusLoadRequest
Returns

Promise<CorpusLoadResponse<Document<DocumentMetadata>>>

Defined in

ai-jsx/src/batteries/docs.tsx:185


Parser

Ƭ Parser<DocumentMetadata>: (raw: RawDocument) => Promise<Document<DocumentMetadata>>

Type parameters

NameType
DocumentMetadataextends Jsonifiable = Jsonifiable

Type declaration

▸ (raw): Promise<Document<DocumentMetadata>>

A function that parses raw documents to produce text documents that can be used by an LLM.

Parameters
NameType
rawRawDocument
Returns

Promise<Document<DocumentMetadata>>

Defined in

ai-jsx/src/batteries/docs.tsx:67


QAWithCitationsResult

Ƭ QAWithCitationsResult: Partial<z.infer<typeof ResultSchema>>

Defined in

ai-jsx/src/batteries/docs.tsx:856


RawLoader

Ƭ RawLoader: (request: CorpusLoadRequest) => Promise<CorpusLoadResponse<RawDocument>>

Type declaration

▸ (request): Promise<CorpusLoadResponse<RawDocument>>

A function responsible for loading a corpus when parsing is handled separately.

Parameters
NameType
requestCorpusLoadRequest
Returns

Promise<CorpusLoadResponse<RawDocument>>

Defined in

ai-jsx/src/batteries/docs.tsx:190


Vectorizer

Ƭ Vectorizer<DocumentMetadata, ChunkMetadata>: (documents: Document<DocumentMetadata>[]) => Promise<EmbeddedChunk<ChunkMetadata>[]>

Type parameters

NameType
DocumentMetadataextends Jsonifiable = Jsonifiable
ChunkMetadataextends Jsonifiable = Jsonifiable

Type declaration

▸ (documents): Promise<EmbeddedChunk<ChunkMetadata>[]>

A function that converts documents into EmbeddedChunks.

See

asVectorizer

Parameters
NameType
documentsDocument<DocumentMetadata>[]
Returns

Promise<EmbeddedChunk<ChunkMetadata>[]>

Defined in

ai-jsx/src/batteries/docs.tsx:346

Functions

DefaultFormatter

DefaultFormatter(«destructured»): Element

A default component for formatting document chunks.

Parameters

NameType
«destructured»Object
› docScoredChunk<Jsonifiable>

Returns

Element

Defined in

ai-jsx/src/batteries/docs.tsx:763


DocsQA

DocsQA<ChunkMetadata>(props): Promise<Element>

A component that can be used to answer questions about documents. This is a very common usecase for LLMs.

Example

  <DocsQA question="What was Hurricane Katrina?" corpus={corpus} chunkLimit={5} chunkFormatter={GetChunk} />

Type parameters

NameType
ChunkMetadataextends Jsonifiable = Jsonifiable

Parameters

NameType
propsDocsQAProps<ChunkMetadata>

Returns

Promise<Element>

Defined in

ai-jsx/src/batteries/docs.tsx:831


DocsQAWithCitations

DocsQAWithCitations<ChunkMetadata>(props, «destructured»): AsyncGenerator<Node, Node, unknown>

Similar to DocsQA, but encourages the LLM to return citations for its answer.

Type parameters

NameType
ChunkMetadataextends Jsonifiable = Jsonifiable

Parameters

NameType
propsDocsQAWithCitationsProps<ChunkMetadata>
«destructured»ComponentContext

Returns

AsyncGenerator<Node, Node, unknown>

Defined in

ai-jsx/src/batteries/docs.tsx:869


asVectorizer

asVectorizer<DocumentMetadata, ChunkMetadata>(chunker, embedding): (docs: Document<DocumentMetadata>[]) => Promise<EmbeddedChunk<ChunkMetadata>[]>

Converts a Chunker + Embedding into a unified Vectorizer function.

Type parameters

NameType
DocumentMetadataextends Jsonifiable = Jsonifiable
ChunkMetadataextends Jsonifiable = Jsonifiable

Parameters

NameType
chunkerChunker<DocumentMetadata, ChunkMetadata>
embeddingEmbedding

Returns

fn

▸ (docs): Promise<EmbeddedChunk<ChunkMetadata>[]>

Parameters
NameType
docsDocument<DocumentMetadata>[]
Returns

Promise<EmbeddedChunk<ChunkMetadata>[]>

Defined in

ai-jsx/src/batteries/docs.tsx:352


defaultChunker

defaultChunker(document): Promise<Chunk<Jsonifiable>[]>

A simple token size based text chunker. This is a good starting point for text documents.

Parameters

NameType
documentDocument<Jsonifiable>

Returns

Promise<Chunk<Jsonifiable>[]>

Defined in

ai-jsx/src/batteries/docs.tsx:264


makeChunker

makeChunker<Metadata>(chunkSize, chunkOverlap): Chunker<Metadata, Metadata>

Creates a Chunker with the given parameters.

Type parameters

NameType
Metadataextends Jsonifiable = Jsonifiable

Parameters

NameType
chunkSizenumber
chunkOverlapnumber

Returns

Chunker<Metadata, Metadata>

Defined in

ai-jsx/src/batteries/docs.tsx:267


staticLoader

staticLoader<DocumentMetadata>(documents, pageSize?): Loader<DocumentMetadata>

A Loader that provides a static set of in-memory documents, optionally with pagination.

Type parameters

NameType
DocumentMetadataextends Jsonifiable = Jsonifiable

Parameters

NameType
documentsDocument<DocumentMetadata>[]
pageSize?number

Returns

Loader<DocumentMetadata>

Defined in

ai-jsx/src/batteries/docs.tsx:249


toLoader

toLoader<DocumentMetadata>(rawLoader, parser?): Loader<DocumentMetadata>

Combines a RawLoader with a Parser to produce a Loader.

Type parameters

NameType
DocumentMetadataextends Jsonifiable = Jsonifiable

Parameters

NameTypeDefault value
rawLoaderRawLoaderundefined
parserParser<DocumentMetadata>defaultParser

Returns

Loader<DocumentMetadata>

Defined in

ai-jsx/src/batteries/docs.tsx:193