langchain_experimental.text_splitter.SemanticChunker

class langchain_experimental.text_splitter.SemanticChunker(embeddings: Embeddings, buffer_size: int = 1, add_start_index: bool = False, breakpoint_threshold_type: Literal['percentile', 'standard_deviation', 'interquartile'] = 'percentile', breakpoint_threshold_amount: Optional[float] = None, number_of_chunks: Optional[int] = None, sentence_split_regex: str = '(?<=[.?!])\\s+')[source]

根据语义相似性分割文本。

参考自Greg Kamradt的优秀笔记: https://github.com/FullStackRetrieval-com/RetrievalTutorials/blob/main/tutorials/LevelsOfTextSplitting/5_Levels_Of_Text_Splitting.ipynb

所有功绩归于他。

在高层次上,这将文本分割为句子,然后分组为三句一组,然后合并在嵌入空间中相似的句子。

Methods

__init__(embeddings[, buffer_size, ...])

atransform_documents(documents, **kwargs)

异步转换文档列表。

create_documents(texts[, metadatas])

从文本列表创建文档。

split_documents(documents)

拆分文档.

split_text(text)

transform_documents(documents, **kwargs)

通过分割文档的序列来转换它们。

Parameters
  • embeddings (Embeddings) –

  • buffer_size (int) –

  • add_start_index (bool) –

  • breakpoint_threshold_type (Literal['percentile', 'standard_deviation', 'interquartile']) –

  • breakpoint_threshold_amount (Optional[float]) –

  • number_of_chunks (Optional[int]) –

  • sentence_split_regex (str) –

__init__(embeddings: Embeddings, buffer_size: int = 1, add_start_index: bool = False, breakpoint_threshold_type: Literal['percentile', 'standard_deviation', 'interquartile'] = 'percentile', breakpoint_threshold_amount: Optional[float] = None, number_of_chunks: Optional[int] = None, sentence_split_regex: str = '(?<=[.?!])\\s+')[source]
Parameters
  • embeddings (Embeddings) –

  • buffer_size (int) –

  • add_start_index (bool) –

  • breakpoint_threshold_type (Literal['percentile', 'standard_deviation', 'interquartile']) –

  • breakpoint_threshold_amount (Optional[float]) –

  • number_of_chunks (Optional[int]) –

  • sentence_split_regex (str) –

async atransform_documents(documents: Sequence[Document], **kwargs: Any) Sequence[Document]

异步转换文档列表。

参数:

documents:要转换的文档序列。

返回:

转换后的文档列表。

Parameters
  • documents (Sequence[Document]) –

  • kwargs (Any) –

Return type

Sequence[Document]

create_documents(texts: List[str], metadatas: Optional[List[dict]] = None) List[Document][source]

从文本列表创建文档。

Parameters
  • texts (List[str]) –

  • metadatas (Optional[List[dict]]) –

Return type

List[Document]

split_documents(documents: Iterable[Document]) List[Document][source]

拆分文档.

Parameters

documents (Iterable[Document]) –

Return type

List[Document]

split_text(text: str) List[str][source]
Parameters

text (str) –

Return type

List[str]

transform_documents(documents: Sequence[Document], **kwargs: Any) Sequence[Document][source]

通过分割文档的序列来转换它们。

Parameters
  • documents (Sequence[Document]) –

  • kwargs (Any) –

Return type

Sequence[Document]

Examples using SemanticChunker