langchain_community.document_loaders.text
.TextLoader¶
- class langchain_community.document_loaders.text.TextLoader(file_path: Union[str, Path], encoding: Optional[str] = None, autodetect_encoding: bool = False)[source]¶
加载文本文件。
- 参数:
file_path:要加载的文件路径。
encoding:要使用的文件编码。如果为`None`,则将使用默认的系统编码。
autodetect_encoding:是否尝试自动检测文件编码,如果指定的编码失败。
使用文件路径进行初始化。
Methods
__init__
(file_path[, encoding, ...])使用文件路径进行初始化。
一个用于文档的惰性加载器。
aload
()将数据加载到文档对象中。
从文件路径加载。
load
()将数据加载到文档对象中。
load_and_split
([text_splitter])加载文档并分割成块。块作为文档返回。
- Parameters
file_path (Union[str, Path]) –
encoding (Optional[str]) –
autodetect_encoding (bool) –
- __init__(file_path: Union[str, Path], encoding: Optional[str] = None, autodetect_encoding: bool = False)[source]¶
使用文件路径进行初始化。
- Parameters
file_path (Union[str, Path]) –
encoding (Optional[str]) –
autodetect_encoding (bool) –
- load_and_split(text_splitter: Optional[TextSplitter] = None) List[Document] ¶
加载文档并分割成块。块作为文档返回。
不要覆盖此方法。应该被视为已弃用!
- 参数:
- text_splitter: 用于分割文档的TextSplitter实例。
默认为RecursiveCharacterTextSplitter。
- 返回:
文档列表。
- Parameters
text_splitter (Optional[TextSplitter]) –
- Return type
List[Document]
Examples using TextLoader¶
# Automatically restart kernel after installs so that your environment can access the new packages
%pip install –upgrade –quiet surrealdb langchain langchain-community
Create collection if running for the first time. If the collection
Establishing a connection to the database is facilitated through the singlestoredb Python connector.
Get an OpenAI token: https://platform.openai.com/account/api-keys
If using the default Docker installation, use this instantiation instead:
Pip install necessary package {#pip-install-necessary-package}
Use Meilisearch vector store to store texts & associated embeddings as vector
from langchain_community.embeddings.openai import OpenAIEmbeddings