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
- Chunk
- Corpus
- CorpusLoadRequest
- CorpusLoadResponse
- CorpusPage
- CorpusPartition
- CorpusStats
- DocsQAProps
- DocsQAWithCitationsProps
- Document
- EmbeddedChunk
- Embedding
- LoadableCorpus
- RawDocument
- ScoredChunk
Type Aliases
Chunker
Ƭ Chunker<DocumentMetadata
, ChunkMetadata
>: (document
: Document
<DocumentMetadata
>) => Promise
<Chunk
<ChunkMetadata
>[]>
Type parameters
Name | Type |
---|---|
DocumentMetadata | extends Jsonifiable = Jsonifiable |
ChunkMetadata | extends 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
Name | Type |
---|---|
document | Document <DocumentMetadata > |
Returns
Promise
<Chunk
<ChunkMetadata
>[]>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:259
Loader
Ƭ Loader<DocumentMetadata
>: (request
: CorpusLoadRequest
) => Promise
<CorpusLoadResponse
<Document
<DocumentMetadata
>>>
Type parameters
Name | Type |
---|---|
DocumentMetadata | extends Jsonifiable = Jsonifiable |
Type declaration
▸ (request
): Promise
<CorpusLoadResponse
<Document
<DocumentMetadata
>>>
A function responsible for loading and parsing a corpus.
Parameters
Name | Type |
---|---|
request | CorpusLoadRequest |
Returns
Promise
<CorpusLoadResponse
<Document
<DocumentMetadata
>>>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:183
Parser
Ƭ Parser<DocumentMetadata
>: (raw
: RawDocument
) => Promise
<Document
<DocumentMetadata
>>
Type parameters
Name | Type |
---|---|
DocumentMetadata | extends 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
Name | Type |
---|---|
raw | RawDocument |
Returns
Promise
<Document
<DocumentMetadata
>>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:65
QAWithCitationsResult
Ƭ QAWithCitationsResult: Partial
<z.infer
<typeof ResultSchema
>>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:823
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
Name | Type |
---|---|
request | CorpusLoadRequest |
Returns
Promise
<CorpusLoadResponse
<RawDocument
>>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:188
Vectorizer
Ƭ Vectorizer<DocumentMetadata
, ChunkMetadata
>: (documents
: Document
<DocumentMetadata
>[]) => Promise
<EmbeddedChunk
<ChunkMetadata
>[]>
Type parameters
Name | Type |
---|---|
DocumentMetadata | extends Jsonifiable = Jsonifiable |
ChunkMetadata | extends Jsonifiable = Jsonifiable |
Type declaration
▸ (documents
): Promise
<EmbeddedChunk
<ChunkMetadata
>[]>
A function that converts documents into EmbeddedChunks.
See
asVectorizer
Parameters
Name | Type |
---|---|
documents | Document <DocumentMetadata >[] |
Returns
Promise
<EmbeddedChunk
<ChunkMetadata
>[]>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:344
Functions
DefaultFormatter
▸ DefaultFormatter(«destructured»
): Element
A default component for formatting document chunks.
Parameters
Name | Type |
---|---|
«destructured» | Object |
› doc | ScoredChunk <Jsonifiable > |
Returns
Element
Defined in
packages/ai-jsx/src/batteries/docs.tsx:730
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
Name | Type |
---|---|
ChunkMetadata | extends Jsonifiable = Jsonifiable |
Parameters
Name | Type |
---|---|
props | DocsQAProps <ChunkMetadata > |
Returns
Promise
<Element
>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:798
DocsQAWithCitations
▸ DocsQAWithCitations<ChunkMetadata
>(props
, «destructured»
): AsyncGenerator
<Node
, Node
, unknown
>
Similar to DocsQA, but encourages the LLM to return citations for its answer.
Type parameters
Name | Type |
---|---|
ChunkMetadata | extends Jsonifiable = Jsonifiable |
Parameters
Name | Type |
---|---|
props | DocsQAWithCitationsProps <ChunkMetadata > |
«destructured» | ComponentContext |
Returns
AsyncGenerator
<Node
, Node
, unknown
>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:836
asVectorizer
▸ asVectorizer<DocumentMetadata
, ChunkMetadata
>(chunker
, embedding
): (docs
: Document
<DocumentMetadata
>[]) => Promise
<EmbeddedChunk
<ChunkMetadata
>[]>
Converts a Chunker + Embedding into a unified Vectorizer function.
Type parameters
Name | Type |
---|---|
DocumentMetadata | extends Jsonifiable = Jsonifiable |
ChunkMetadata | extends Jsonifiable = Jsonifiable |
Parameters
Name | Type |
---|---|
chunker | Chunker <DocumentMetadata , ChunkMetadata > |
embedding | Embedding |
Returns
fn
▸ (docs
): Promise
<EmbeddedChunk
<ChunkMetadata
>[]>
Parameters
Name | Type |
---|---|
docs | Document <DocumentMetadata >[] |
Returns
Promise
<EmbeddedChunk
<ChunkMetadata
>[]>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:350
defaultChunker
▸ defaultChunker(document
): Promise
<Chunk
<Jsonifiable
>[]>
A simple token size based text chunker. This is a good starting point for text documents.
Parameters
Name | Type |
---|---|
document | Document <Jsonifiable > |
Returns
Promise
<Chunk
<Jsonifiable
>[]>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:262
makeChunker
▸ makeChunker<Metadata
>(chunkSize
, chunkOverlap
): Chunker
<Metadata
, Metadata
>
Creates a Chunker with the given parameters.
Type parameters
Name | Type |
---|---|
Metadata | extends Jsonifiable = Jsonifiable |
Parameters
Name | Type |
---|---|
chunkSize | number |
chunkOverlap | number |
Returns
Chunker
<Metadata
, Metadata
>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:265
staticLoader
▸ staticLoader<DocumentMetadata
>(documents
, pageSize?
): Loader
<DocumentMetadata
>
A Loader that provides a static set of in-memory documents, optionally with pagination.
Type parameters
Name | Type |
---|---|
DocumentMetadata | extends Jsonifiable = Jsonifiable |
Parameters
Name | Type |
---|---|
documents | Document <DocumentMetadata >[] |
pageSize? | number |
Returns
Loader
<DocumentMetadata
>
Defined in
packages/ai-jsx/src/batteries/docs.tsx:247
toLoader
▸ toLoader<DocumentMetadata
>(rawLoader
, parser?
): Loader
<DocumentMetadata
>
Combines a RawLoader with a Parser to produce a Loader.
Type parameters
Name | Type |
---|---|
DocumentMetadata | extends Jsonifiable = Jsonifiable |
Parameters
Name | Type | Default value |
---|---|---|
rawLoader | RawLoader | undefined |
parser | Parser <DocumentMetadata > | defaultParser |
Returns
Loader
<DocumentMetadata
>