fabricatio_novel.actions.novel_rag

Novel RAG actions for retrieval-augmented generation.

Classes

RetrieveWritingStyles

Retrieve writing style documents from LanceDB based on a query.

InjectWritingStyleToScript

Inject retrieved writing style documents into scripts.

GenerateChaptersFromScriptsWithRAG

Generate chapter contents from scripts with RAG writing style augmentation.

StoreWritingStyleTexts

Store writing style reference texts from files into LanceDB.

Module Contents

class fabricatio_novel.actions.novel_rag.RetrieveWritingStyles(/, **data: Any)

Bases: fabricatio_novel.capabilities.novel_rag.NovelComposeRAG, fabricatio_core.Action

Retrieve writing style documents from LanceDB based on a query.

writing_style_query: str | None = None

The query text used to search for relevant writing style documents.

writing_style_fetch_config: fabricatio_novel.models.novel_rag.WritingStyleFetchConfig | None = None

Optional fetch configuration override for writing style retrieval.

output_key: str = 'writing_styles'

Key under which the retrieved writing style documents will be stored in context.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

class fabricatio_novel.actions.novel_rag.InjectWritingStyleToScript(/, **data: Any)

Bases: fabricatio_novel.capabilities.novel_rag.NovelComposeRAG, fabricatio_core.Action

Inject retrieved writing style documents into scripts.

Handles both script-level (global_prompt) and scene-level (per-scene prompt) injection. Script-level uses the provided writing_styles; scene-level fetches per-scene docs from LanceDB based on each scene’s description.

novel_scripts: List[fabricatio_novel.models.scripting.Script] | None = None

The list of chapter scripts to augment with writing style guidance.

writing_styles: List[fabricatio_novel.models.novel_rag.WritingStyleDocument] | None = None

Global writing style documents to inject into each script’s global_prompt.

writing_style_fetch_config: fabricatio_novel.models.novel_rag.WritingStyleFetchConfig | None = None

Optional fetch configuration override for scene-level writing style retrieval.

output_key: str = 'novel_scripts'

Key under which the augmented scripts will be stored in context (overwrites original).

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

class fabricatio_novel.actions.novel_rag.GenerateChaptersFromScriptsWithRAG(/, **data: Any)

Bases: fabricatio_novel.capabilities.novel_rag.NovelComposeRAG, fabricatio_core.Action

Generate chapter contents from scripts with RAG writing style augmentation.

Mirrors GenerateChaptersFromScripts but inherits NovelComposeRAG so that create_chapters() applies script-level and scene-level style injection before generating prose. Passes writing_style_fetch_config through kwargs.

novel_draft: fabricatio_novel.models.draft.NovelDraft | None = None

The novel draft (for language, metadata).

novel_scripts: List[fabricatio_novel.models.scripting.Script] | None = None

The list of chapter scripts to expand into full text.

novel_characters: List[fabricatio_character.models.character.CharacterCard] | None = None

The list of characters to provide context.

chapter_guidance: str | None = None

Guidance for writing chapter.

writing_style_query: str | None = None

Query text for writing style retrieval. Used to build default fetch config.

writing_style_fetch_config: fabricatio_novel.models.novel_rag.WritingStyleFetchConfig | None = None

Optional fetch configuration override for writing style retrieval.

output_key: str = 'novel_chapter_contents'

Key under which the generated chapter contents will be stored in context.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

class fabricatio_novel.actions.novel_rag.StoreWritingStyleTexts(/, **data: Any)

Bases: fabricatio_rag.actions.db.StoreTextFile, fabricatio_novel.capabilities.novel_rag.NovelComposeRAG

Store writing style reference texts from files into LanceDB.

Reads text files, splits them into chunks, and indexes them in the LanceDB vector store for later RAG retrieval. This is a standalone ingestion workflow — it does not generate novel content.

store_model: Type[fabricatio_novel.models.novel_rag.WritingStyleDocument]
output_key: str = 'stored_count'

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

store_config: fabricatio_lancedb.capabilities.lancedb.LancedbAddRAGConfig | None = None