fabricatio_typst.actions.article_rag

A module for writing articles using RAG (Retrieval-Augmented Generation) capabilities.

Attributes

TYPST_CITE_USAGE

TYPST_MATH_USAGE

Classes

WriteArticleContentRAG

Write an article based on the provided outline.

ArticleConsultRAG

Write an article based on the provided outline.

TweakArticleLancedbRAG

Write an article based on the provided outline.

ChunkArticle

Chunk an article into smaller chunks.

StoreArticleEssence

Store ArticleEssence instances into LanceDB.

Module Contents

fabricatio_typst.actions.article_rag.TYPST_CITE_USAGE = Multiline-String
Show Value
"""citation number is REQUIRED to cite any reference!'
Legal citing syntax examples(seperated by |): [[1]]|[[1,2]]|[[1-3]]|[[12,13-15]]|[[1-3,5-7]]
Illegal citing syntax examples(seperated by |): [[1],[2],[3]]|[[1],[1-2]]
You SHALL not cite a single reference more than once!It's recommended to cite multiple references that supports your conclusion at a time.
"""
fabricatio_typst.actions.article_rag.TYPST_MATH_USAGE = Multiline-String
Show Value
"""Wrap inline expression with '\(' and '\)',like '\(>5m\)' '\(89%\)', and wrap block equation with '\[' and '\]'.
In addition to that, you can add a label outside the block equation which can be used as a cross reference identifier, the label is a string wrapped in `<` and `>` like `<energy-release-rate-equation>`.Note that the label string should be a summarizing title for the equation being labeled and should never be written within the formula block.
you can refer to that label by using the syntax with prefix of `@eqt:`, which indicate that this notation is citing a label from the equations. For example ' @eqt:energy-release-rate-equation ' DO remember that the notation shall have both suffixed and prefixed space char which enable the compiler to distinguish the notation from the plaintext.Below is two usage example:
```typst
See @eqt:mass-energy-equation , it's the foundation of physics.
\[
E = m c^2
\]  <mass-energy-equation>


In @eqt:mass-energy-equation , \(m\) stands for mass, \(c\) stands for speed of light, and \(E\) stands for energy.
```
"""
class fabricatio_typst.actions.article_rag.WriteArticleContentRAG(/, **data: Any)

Bases: fabricatio_core.models.action.Action, fabricatio_capabilities.capabilities.extract.Extract, fabricatio_typst.capabilities.citation_rag.CitationLancedbRAG

Write an article based on the provided outline.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

search_increment_multiplier: float = 1.6

The increment multiplier of the search increment.

ref_limit: int = 35

The limit of references to be retrieved

threshold: float = 0.62

The threshold of relevance

extractor_model: fabricatio_core.models.kwargs_types.LLMKwargs

The model to use for extracting the content from the retrieved references.

query_model: fabricatio_core.models.kwargs_types.ListStringKwargs | None = None

The model to use for querying the database

supervisor: bool = False

Whether to use supervisor mode

result_per_query: pydantic.PositiveInt = 4

The number of results to be returned per query.

cite_req: str = Multiline-String
Show Value
"""citation number is REQUIRED to cite any reference!'
Legal citing syntax examples(seperated by |): [[1]]|[[1,2]]|[[1-3]]|[[12,13-15]]|[[1-3,5-7]]
Illegal citing syntax examples(seperated by |): [[1],[2],[3]]|[[1],[1-2]]
You SHALL not cite a single reference more than once!It's recommended to cite multiple references that supports your conclusion at a time.
"""

The req of the write article content.

math_req: str = Multiline-String
Show Value
"""Wrap inline expression with '\(' and '\)',like '\(>5m\)' '\(89%\)', and wrap block equation with '\[' and '\]'.
In addition to that, you can add a label outside the block equation which can be used as a cross reference identifier, the label is a string wrapped in `<` and `>` like `<energy-release-rate-equation>`.Note that the label string should be a summarizing title for the equation being labeled and should never be written within the formula block.
you can refer to that label by using the syntax with prefix of `@eqt:`, which indicate that this notation is citing a label from the equations. For example ' @eqt:energy-release-rate-equation ' DO remember that the notation shall have both suffixed and prefixed space char which enable the compiler to distinguish the notation from the plaintext.Below is two usage example:
```typst
See @eqt:mass-energy-equation , it's the foundation of physics.
\[
E = m c^2
\]  <mass-energy-equation>


In @eqt:mass-energy-equation , \(m\) stands for mass, \(c\) stands for speed of light, and \(E\) stands for energy.
```
"""

The req of the write article content.

async extract_new_subsec(subsec: fabricatio_typst.models.article_main.ArticleSubsection, raw_paras: str, cm: fabricatio_typst.models.article_rag.CitationManager) fabricatio_typst.models.article_main.ArticleSubsection

Extract the new subsec.

async write_raw(article: fabricatio_typst.models.article_main.Article, article_outline: fabricatio_typst.models.article_outline.ArticleOutline, chap: fabricatio_typst.models.article_main.ArticleChapter, sec: fabricatio_typst.models.article_main.ArticleSection, subsec: fabricatio_typst.models.article_main.ArticleSubsection, cm: fabricatio_typst.models.article_rag.CitationManager, extra_instruction: str = '') str

Write the raw paragraphs of the subsec.

async search_database(article: fabricatio_typst.models.article_main.Article, article_outline: fabricatio_typst.models.article_outline.ArticleOutline, chap: fabricatio_typst.models.article_main.ArticleChapter, sec: fabricatio_typst.models.article_main.ArticleSection, subsec: fabricatio_typst.models.article_main.ArticleSubsection, cm: fabricatio_typst.models.article_rag.CitationManager, extra_instruction: str = '') None

Search database for related references.

class fabricatio_typst.actions.article_rag.ArticleConsultRAG(/, **data: Any)

Bases: fabricatio_core.models.action.Action, fabricatio_typst.capabilities.citation_rag.CitationLancedbRAG

Write an article based on the provided outline.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

output_key: str = 'consult_count'

The key used to store this action’s output in the context dictionary.

search_increment_multiplier: float = 1.6

The multiplier to increase the limit of references to retrieve per query.

ref_limit: int = 26

The final limit of references.

ref_per_q: int = 13

The limit of references to retrieve per query.

similarity_threshold: float = 0.62

The similarity threshold of references to retrieve.

ref_q_model: fabricatio_core.models.kwargs_types.ListStringKwargs = None

The model to use for refining query.

req: str = Multiline-String
Show Value
"""citation number is REQUIRED to cite any reference!'
Legal citing syntax examples(seperated by |): [[1]]|[[1,2]]|[[1-3]]|[[12,13-15]]|[[1-3,5-7]]
Illegal citing syntax examples(seperated by |): [[1],[2],[3]]|[[1],[1-2]]
You SHALL not cite a single reference more than once!It's recommended to cite multiple references that supports your conclusion at a time.
"""

The request for the rag model.

class fabricatio_typst.actions.article_rag.TweakArticleLancedbRAG(/, **data: Any)

Bases: fabricatio_core.models.action.Action, fabricatio_lancedb.capabilities.lancedb.LancedbRAG, fabricatio_rule.capabilities.censor.Censor

Write an article based on the provided outline.

This class inherits from Action, RAG, and Censor to provide capabilities for writing and refining articles using Retrieval-Augmented Generation (RAG) techniques. It processes an article outline, enhances subsections by searching for related references, and applies censoring rules to ensure compliance with the provided ruleset.

output_key: str = 'rag_tweaked_article'

The key used to store the output of the action.

ruleset: fabricatio_rule.models.rule.RuleSet | None = None

The ruleset to be used for censoring the article.

ref_limit: int = 30

The limit of references to be retrieved

class fabricatio_typst.actions.article_rag.ChunkArticle(/, **data: Any)

Bases: fabricatio_core.models.action.Action

Chunk an article into smaller chunks.

output_key: str = 'article_chunks'

The key used to store the output of the action.

max_chunk_size: int | None = None

The maximum size of each chunk.

max_overlapping_rate: float | None = None

The maximum overlapping rate between chunks.

class fabricatio_typst.actions.article_rag.StoreArticleEssence

Bases: fabricatio_rag.actions.db.StoreDocuments[fabricatio_typst.models.article_rag.ArticleEssenceStorable, fabricatio_typst.models.article_rag.ArticleEssenceStorable, fabricatio_lancedb.capabilities.lancedb.LancedbAddRAGConfig, fabricatio_lancedb.capabilities.lancedb.LancedbFetchRAGConfig[fabricatio_typst.models.article_rag.ArticleEssenceStorable]], fabricatio_lancedb.capabilities.lancedb.LancedbRAG[fabricatio_typst.models.article_rag.ArticleEssenceStorable, fabricatio_lancedb.capabilities.lancedb.LancedbAddRAGConfig, fabricatio_lancedb.capabilities.lancedb.LancedbFetchRAGConfig[fabricatio_typst.models.article_rag.ArticleEssenceStorable]]

Store ArticleEssence instances into LanceDB.