id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
59
127
fe18070e4f36-22
load_questions_and_answers(url_override: Optional[str] = None) → List[langchain.schema.Document][source]# static load_suggestions(query: str = '', doc_type: str = 'all') → List[langchain.schema.Document][source]# class langchain.document_loaders.IMSDbLoader(web_path: Union[str, List[str]], header_template: Optional[dict] = None)[source]# Loader that loads IMSDb webpages. load() → List[langchain.schema.Document][source]# Load webpage. class langchain.document_loaders.ImageCaptionLoader(path_images: Union[str, List[str]], blip_processor: str = 'Salesforce/blip-image-captioning-base', blip_model: str = 'Salesforce/blip-image-captioning-base')[source]# Loader that loads the captions of an image load() → List[langchain.schema.Document][source]# Load from a list of image files class langchain.document_loaders.IuguLoader(resource: str, api_token: Optional[str] = None)[source]# load() → List[langchain.schema.Document][source]# Load data into document objects. class langchain.document_loaders.JSONLoader(file_path: Union[str, pathlib.Path], jq_schema: str, content_key: Optional[str] = None, metadata_func: Optional[Callable[[Dict, Dict], Dict]] = None, text_content: bool = True)[source]# Loads a JSON file and references a jq schema provided to load the text into documents. Example [{“text”: …}, {“text”: …}, {“text”: …}] -> schema = .[].text {“key”: [{“text”: …}, {“text”: …}, {“text”: …}]} -> schema = .key[].text [“”, “”, “”] -> schema = .[]
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-23
[“”, “”, “”] -> schema = .[] load() → List[langchain.schema.Document][source]# Load and return documents from the JSON file. class langchain.document_loaders.JoplinLoader(access_token: Optional[str] = None, port: int = 41184, host: str = 'localhost')[source]# Loader that fetches notes from Joplin. In order to use this loader, you need to have Joplin running with the Web Clipper enabled (look for “Web Clipper” in the app settings). To get the access token, you need to go to the Web Clipper options and under “Advanced Options” you will find the access token. You can find more information about the Web Clipper service here: https://joplinapp.org/clipper/ lazy_load() → Iterator[langchain.schema.Document][source]# A lazy loader for document content. load() → List[langchain.schema.Document][source]# Load data into document objects. class langchain.document_loaders.MWDumpLoader(file_path: str, encoding: Optional[str] = 'utf8')[source]# Load MediaWiki dump from XML file .. rubric:: Example from langchain.document_loaders import MWDumpLoader loader = MWDumpLoader( file_path="myWiki.xml", encoding="utf8" ) docs = loader.load() from langchain.text_splitter import RecursiveCharacterTextSplitter text_splitter = RecursiveCharacterTextSplitter( chunk_size=1000, chunk_overlap=0 ) texts = text_splitter.split_documents(docs) Parameters file_path (str) – XML local file path encoding (str, optional) – Charset encoding, defaults to “utf8”
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-24
encoding (str, optional) – Charset encoding, defaults to “utf8” load() → List[langchain.schema.Document][source]# Load from file path. class langchain.document_loaders.MastodonTootsLoader(mastodon_accounts: Sequence[str], number_toots: Optional[int] = 100, exclude_replies: bool = False, access_token: Optional[str] = None, api_base_url: str = 'https://mastodon.social')[source]# Mastodon toots loader. load() → List[langchain.schema.Document][source]# Load toots into documents. class langchain.document_loaders.MathpixPDFLoader(file_path: str, processed_file_format: str = 'mmd', max_wait_time_seconds: int = 500, should_clean_pdf: bool = False, **kwargs: Any)[source]# clean_pdf(contents: str) → str[source]# property data: dict# get_processed_pdf(pdf_id: str) → str[source]# property headers: dict# load() → List[langchain.schema.Document][source]# Load data into document objects. send_pdf() → str[source]# property url: str# wait_for_processing(pdf_id: str) → None[source]# class langchain.document_loaders.MaxComputeLoader(query: str, api_wrapper: langchain.utilities.max_compute.MaxComputeAPIWrapper, *, page_content_columns: Optional[Sequence[str]] = None, metadata_columns: Optional[Sequence[str]] = None)[source]# Loads a query result from Alibaba Cloud MaxCompute table into documents. classmethod from_params(query: str, endpoint: str, project: str, *, access_id: Optional[str] = None, secret_access_key: Optional[str] = None, **kwargs: Any) → langchain.document_loaders.max_compute.MaxComputeLoader[source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-25
Convenience constructor that builds the MaxCompute API wrapper fromgiven parameters. Parameters query – SQL query to execute. endpoint – MaxCompute endpoint. project – A project is a basic organizational unit of MaxCompute, which is similar to a database. access_id – MaxCompute access ID. Should be passed in directly or set as the environment variable MAX_COMPUTE_ACCESS_ID. secret_access_key – MaxCompute secret access key. Should be passed in directly or set as the environment variable MAX_COMPUTE_SECRET_ACCESS_KEY. lazy_load() → Iterator[langchain.schema.Document][source]# A lazy loader for document content. load() → List[langchain.schema.Document][source]# Load data into document objects. class langchain.document_loaders.ModernTreasuryLoader(resource: str, organization_id: Optional[str] = None, api_key: Optional[str] = None)[source]# load() → List[langchain.schema.Document][source]# Load data into document objects. class langchain.document_loaders.NotebookLoader(path: str, include_outputs: bool = False, max_output_length: int = 10, remove_newline: bool = False, traceback: bool = False)[source]# Loader that loads .ipynb notebook files. load() → List[langchain.schema.Document][source]# Load documents. class langchain.document_loaders.NotionDBLoader(integration_token: str, database_id: str, request_timeout_sec: Optional[int] = 10)[source]# Notion DB Loader. Reads content from pages within a Noton Database. :param integration_token: Notion integration token. :type integration_token: str :param database_id: Notion database id. :type database_id: str :param request_timeout_sec: Timeout for Notion requests in seconds. :type request_timeout_sec: int
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-26
:type request_timeout_sec: int load() → List[langchain.schema.Document][source]# Load documents from the Notion database. :returns: List of documents. :rtype: List[Document] load_page(page_id: str) → langchain.schema.Document[source]# Read a page. class langchain.document_loaders.NotionDirectoryLoader(path: str)[source]# Loader that loads Notion directory dump. load() → List[langchain.schema.Document][source]# Load documents. class langchain.document_loaders.ObsidianLoader(path: str, encoding: str = 'UTF-8', collect_metadata: bool = True)[source]# Loader that loads Obsidian files from disk. FRONT_MATTER_REGEX = re.compile('^---\\n(.*?)\\n---\\n', re.MULTILINE|re.DOTALL)# load() → List[langchain.schema.Document][source]# Load documents. pydantic model langchain.document_loaders.OneDriveFileLoader[source]# field file: File [Required]# load() → List[langchain.schema.Document][source]# Load Documents pydantic model langchain.document_loaders.OneDriveLoader[source]# field auth_with_token: bool = False# field drive_id: str [Required]# field folder_path: Optional[str] = None# field object_ids: Optional[List[str]] = None# field settings: langchain.document_loaders.onedrive._OneDriveSettings [Optional]# load() → List[langchain.schema.Document][source]# Loads all supported document files from the specified OneDrive drive a nd returns a list of Document objects. Returns A list of Document objects representing the loaded documents. Return type List[Document] Raises ValueError – If the specified drive ID
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-27
Return type List[Document] Raises ValueError – If the specified drive ID does not correspond to a drive in the OneDrive storage. – class langchain.document_loaders.OnlinePDFLoader(file_path: str)[source]# Loader that loads online PDFs. load() → List[langchain.schema.Document][source]# Load documents. class langchain.document_loaders.OutlookMessageLoader(file_path: str)[source]# Loader that loads Outlook Message files using extract_msg. TeamMsgExtractor/msg-extractor load() → List[langchain.schema.Document][source]# Load data into document objects. class langchain.document_loaders.PDFMinerLoader(file_path: str)[source]# Loader that uses PDFMiner to load PDF files. lazy_load() → Iterator[langchain.schema.Document][source]# Lazily lod documents. load() → List[langchain.schema.Document][source]# Eagerly load the content. class langchain.document_loaders.PDFMinerPDFasHTMLLoader(file_path: str)[source]# Loader that uses PDFMiner to load PDF files as HTML content. load() → List[langchain.schema.Document][source]# Load file. class langchain.document_loaders.PDFPlumberLoader(file_path: str, text_kwargs: Optional[Mapping[str, Any]] = None)[source]# Loader that uses pdfplumber to load PDF files. load() → List[langchain.schema.Document][source]# Load file. langchain.document_loaders.PagedPDFSplitter# alias of langchain.document_loaders.pdf.PyPDFLoader
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-28
alias of langchain.document_loaders.pdf.PyPDFLoader class langchain.document_loaders.PlaywrightURLLoader(urls: List[str], continue_on_failure: bool = True, headless: bool = True, remove_selectors: Optional[List[str]] = None)[source]# Loader that uses Playwright and to load a page and unstructured to load the html. This is useful for loading pages that require javascript to render. urls# List of URLs to load. Type List[str] continue_on_failure# If True, continue loading other URLs on failure. Type bool headless# If True, the browser will run in headless mode. Type bool load() → List[langchain.schema.Document][source]# Load the specified URLs using Playwright and create Document instances. Returns A list of Document instances with loaded content. Return type List[Document] class langchain.document_loaders.PsychicLoader(api_key: str, connector_id: str, connection_id: str)[source]# Loader that loads documents from Psychic.dev. load() → List[langchain.schema.Document][source]# Load documents. class langchain.document_loaders.PyMuPDFLoader(file_path: str)[source]# Loader that uses PyMuPDF to load PDF files. load(**kwargs: Optional[Any]) → List[langchain.schema.Document][source]# Load file. class langchain.document_loaders.PyPDFDirectoryLoader(path: str, glob: str = '**/[!.]*.pdf', silent_errors: bool = False, load_hidden: bool = False, recursive: bool = False)[source]# Loads a directory with PDF files with pypdf and chunks at character level. Loader also stores page numbers in metadatas. load() → List[langchain.schema.Document][source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-29
load() → List[langchain.schema.Document][source]# Load data into document objects. class langchain.document_loaders.PyPDFLoader(file_path: str)[source]# Loads a PDF with pypdf and chunks at character level. Loader also stores page numbers in metadatas. lazy_load() → Iterator[langchain.schema.Document][source]# Lazy load given path as pages. load() → List[langchain.schema.Document][source]# Load given path as pages. class langchain.document_loaders.PyPDFium2Loader(file_path: str)[source]# Loads a PDF with pypdfium2 and chunks at character level. lazy_load() → Iterator[langchain.schema.Document][source]# Lazy load given path as pages. load() → List[langchain.schema.Document][source]# Load given path as pages. class langchain.document_loaders.PySparkDataFrameLoader(spark_session: Optional[SparkSession] = None, df: Optional[Any] = None, page_content_column: str = 'text', fraction_of_memory: float = 0.1)[source]# Load PySpark DataFrames get_num_rows() → Tuple[int, int][source]# Gets the amount of “feasible” rows for the DataFrame lazy_load() → Iterator[langchain.schema.Document][source]# A lazy loader for document content. load() → List[langchain.schema.Document][source]# Load from the dataframe. class langchain.document_loaders.PythonLoader(file_path: str)[source]# Load Python files, respecting any non-default encoding if specified.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-30
Load Python files, respecting any non-default encoding if specified. class langchain.document_loaders.ReadTheDocsLoader(path: Union[str, pathlib.Path], encoding: Optional[str] = None, errors: Optional[str] = None, custom_html_tag: Optional[Tuple[str, dict]] = None, **kwargs: Optional[Any])[source]# Loader that loads ReadTheDocs documentation directory dump. load() → List[langchain.schema.Document][source]# Load documents. class langchain.document_loaders.RedditPostsLoader(client_id: str, client_secret: str, user_agent: str, search_queries: Sequence[str], mode: str, categories: Sequence[str] = ['new'], number_posts: Optional[int] = 10)[source]# Reddit posts loader. Read posts on a subreddit. First you need to go to https://www.reddit.com/prefs/apps/ and create your application load() → List[langchain.schema.Document][source]# Load reddits. class langchain.document_loaders.RoamLoader(path: str)[source]# Loader that loads Roam files from disk. load() → List[langchain.schema.Document][source]# Load documents. class langchain.document_loaders.S3DirectoryLoader(bucket: str, prefix: str = '')[source]# Loading logic for loading documents from s3. load() → List[langchain.schema.Document][source]# Load documents. class langchain.document_loaders.S3FileLoader(bucket: str, key: str)[source]# Loading logic for loading documents from s3. load() → List[langchain.schema.Document][source]# Load documents. class langchain.document_loaders.SRTLoader(file_path: str)[source]# Loader for .srt (subtitle) files.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-31
Loader for .srt (subtitle) files. load() → List[langchain.schema.Document][source]# Load using pysrt file. class langchain.document_loaders.SeleniumURLLoader(urls: List[str], continue_on_failure: bool = True, browser: Literal['chrome', 'firefox'] = 'chrome', binary_location: Optional[str] = None, executable_path: Optional[str] = None, headless: bool = True, arguments: List[str] = [])[source]# Loader that uses Selenium and to load a page and unstructured to load the html. This is useful for loading pages that require javascript to render. urls# List of URLs to load. Type List[str] continue_on_failure# If True, continue loading other URLs on failure. Type bool browser# The browser to use, either ‘chrome’ or ‘firefox’. Type str binary_location# The location of the browser binary. Type Optional[str] executable_path# The path to the browser executable. Type Optional[str] headless# If True, the browser will run in headless mode. Type bool arguments [List[str]] List of arguments to pass to the browser. load() → List[langchain.schema.Document][source]# Load the specified URLs using Selenium and create Document instances. Returns A list of Document instances with loaded content. Return type List[Document] class langchain.document_loaders.SitemapLoader(web_path: str, filter_urls: Optional[List[str]] = None, parsing_function: Optional[Callable] = None, blocksize: Optional[int] = None, blocknum: int = 0, meta_function: Optional[Callable] = None, is_local: bool = False)[source]# Loader that fetches a sitemap and loads those URLs.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-32
Loader that fetches a sitemap and loads those URLs. load() → List[langchain.schema.Document][source]# Load sitemap. parse_sitemap(soup: Any) → List[dict][source]# Parse sitemap xml and load into a list of dicts. class langchain.document_loaders.SlackDirectoryLoader(zip_path: str, workspace_url: Optional[str] = None)[source]# Loader for loading documents from a Slack directory dump. load() → List[langchain.schema.Document][source]# Load and return documents from the Slack directory dump. class langchain.document_loaders.SnowflakeLoader(query: str, user: str, password: str, account: str, warehouse: str, role: str, database: str, schema: str, parameters: Optional[Dict[str, Any]] = None, page_content_columns: Optional[List[str]] = None, metadata_columns: Optional[List[str]] = None)[source]# Loads a query result from Snowflake into a list of documents. Each document represents one row of the result. The page_content_columns are written into the page_content of the document. The metadata_columns are written into the metadata of the document. By default, all columns are written into the page_content and none into the metadata. lazy_load() → Iterator[langchain.schema.Document][source]# A lazy loader for document content. load() → List[langchain.schema.Document][source]# Load data into document objects. class langchain.document_loaders.SpreedlyLoader(access_token: str, resource: str)[source]# load() → List[langchain.schema.Document][source]# Load data into document objects. class langchain.document_loaders.StripeLoader(resource: str, access_token: Optional[str] = None)[source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-33
load() → List[langchain.schema.Document][source]# Load data into document objects. class langchain.document_loaders.TelegramChatApiLoader(chat_entity: Optional[EntityLike] = None, api_id: Optional[int] = None, api_hash: Optional[str] = None, username: Optional[str] = None, file_path: str = 'telegram_data.json')[source]# Loader that loads Telegram chat json directory dump. async fetch_data_from_telegram() → None[source]# Fetch data from Telegram API and save it as a JSON file. load() → List[langchain.schema.Document][source]# Load documents. class langchain.document_loaders.TelegramChatFileLoader(path: str)[source]# Loader that loads Telegram chat json directory dump. load() → List[langchain.schema.Document][source]# Load documents. langchain.document_loaders.TelegramChatLoader# alias of langchain.document_loaders.telegram.TelegramChatFileLoader class langchain.document_loaders.TextLoader(file_path: str, encoding: Optional[str] = None, autodetect_encoding: bool = False)[source]# Load text files. Parameters file_path – Path to the file to load. encoding – File encoding to use. If None, the file will be loaded encoding. (with the default system) – autodetect_encoding – Whether to try to autodetect the file encoding if the specified encoding fails. load() → List[langchain.schema.Document][source]# Load from file path. class langchain.document_loaders.ToMarkdownLoader(url: str, api_key: str)[source]# Loader that loads HTML to markdown using 2markdown. lazy_load() → Iterator[langchain.schema.Document][source]# Lazily load the file.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-34
Lazily load the file. load() → List[langchain.schema.Document][source]# Load file. class langchain.document_loaders.TomlLoader(source: Union[str, pathlib.Path])[source]# A TOML document loader that inherits from the BaseLoader class. This class can be initialized with either a single source file or a source directory containing TOML files. lazy_load() → Iterator[langchain.schema.Document][source]# Lazily load the TOML documents from the source file or directory. load() → List[langchain.schema.Document][source]# Load and return all documents. class langchain.document_loaders.TrelloLoader(client: TrelloClient, board_name: str, *, include_card_name: bool = True, include_comments: bool = True, include_checklist: bool = True, card_filter: Literal['closed', 'open', 'all'] = 'all', extra_metadata: Tuple[str, ...] = ('due_date', 'labels', 'list', 'closed'))[source]# Trello loader. Reads all cards from a Trello board. classmethod from_credentials(board_name: str, *, api_key: Optional[str] = None, token: Optional[str] = None, **kwargs: Any) → langchain.document_loaders.trello.TrelloLoader[source]# Convenience constructor that builds TrelloClient init param for you. Parameters board_name – The name of the Trello board. api_key – Trello API key. Can also be specified as environment variable TRELLO_API_KEY. token – Trello token. Can also be specified as environment variable TRELLO_TOKEN. include_card_name – Whether to include the name of the card in the document. include_comments – Whether to include the comments on the card in the document.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-35
include_comments – Whether to include the comments on the card in the document. include_checklist – Whether to include the checklist on the card in the document. card_filter – Filter on card status. Valid values are “closed”, “open”, “all”. extra_metadata – List of additional metadata fields to include as document metadata.Valid values are “due_date”, “labels”, “list”, “closed”. load() → List[langchain.schema.Document][source]# Loads all cards from the specified Trello board. You can filter the cards, metadata and text included by using the optional parameters. Returns:A list of documents, one for each card in the board. class langchain.document_loaders.TwitterTweetLoader(auth_handler: Union[OAuthHandler, OAuth2BearerHandler], twitter_users: Sequence[str], number_tweets: Optional[int] = 100)[source]# Twitter tweets loader. Read tweets of user twitter handle. First you need to go to https://developer.twitter.com/en/docs/twitter-api /getting-started/getting-access-to-the-twitter-api to get your token. And create a v2 version of the app. classmethod from_bearer_token(oauth2_bearer_token: str, twitter_users: Sequence[str], number_tweets: Optional[int] = 100) → langchain.document_loaders.twitter.TwitterTweetLoader[source]# Create a TwitterTweetLoader from OAuth2 bearer token. classmethod from_secrets(access_token: str, access_token_secret: str, consumer_key: str, consumer_secret: str, twitter_users: Sequence[str], number_tweets: Optional[int] = 100) → langchain.document_loaders.twitter.TwitterTweetLoader[source]# Create a TwitterTweetLoader from access tokens and secrets. load() → List[langchain.schema.Document][source]# Load tweets.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-36
load() → List[langchain.schema.Document][source]# Load tweets. class langchain.document_loaders.UnstructuredAPIFileIOLoader(file: Union[IO, Sequence[IO]], mode: str = 'single', url: str = 'https://api.unstructured.io/general/v0/general', api_key: str = '', **unstructured_kwargs: Any)[source]# Loader that uses the unstructured web API to load file IO objects. class langchain.document_loaders.UnstructuredAPIFileLoader(file_path: Union[str, List[str]] = '', mode: str = 'single', url: str = 'https://api.unstructured.io/general/v0/general', api_key: str = '', **unstructured_kwargs: Any)[source]# Loader that uses the unstructured web API to load files. class langchain.document_loaders.UnstructuredCSVLoader(file_path: str, mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load CSV files. class langchain.document_loaders.UnstructuredEPubLoader(file_path: Union[str, List[str]], mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load epub files. class langchain.document_loaders.UnstructuredEmailLoader(file_path: Union[str, List[str]], mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load email files. class langchain.document_loaders.UnstructuredExcelLoader(file_path: str, mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load Microsoft Excel files. class langchain.document_loaders.UnstructuredFileIOLoader(file: Union[IO, Sequence[IO]], mode: str = 'single', **unstructured_kwargs: Any)[source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-37
Loader that uses unstructured to load file IO objects. class langchain.document_loaders.UnstructuredFileLoader(file_path: Union[str, List[str]], mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load files. class langchain.document_loaders.UnstructuredHTMLLoader(file_path: Union[str, List[str]], mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load HTML files. class langchain.document_loaders.UnstructuredImageLoader(file_path: Union[str, List[str]], mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load image files, such as PNGs and JPGs. class langchain.document_loaders.UnstructuredMarkdownLoader(file_path: Union[str, List[str]], mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load markdown files. class langchain.document_loaders.UnstructuredODTLoader(file_path: str, mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load open office ODT files. class langchain.document_loaders.UnstructuredPDFLoader(file_path: Union[str, List[str]], mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load PDF files. class langchain.document_loaders.UnstructuredPowerPointLoader(file_path: Union[str, List[str]], mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load powerpoint files. class langchain.document_loaders.UnstructuredRTFLoader(file_path: str, mode: str = 'single', **unstructured_kwargs: Any)[source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-38
Loader that uses unstructured to load rtf files. class langchain.document_loaders.UnstructuredURLLoader(urls: List[str], continue_on_failure: bool = True, mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load HTML files. load() → List[langchain.schema.Document][source]# Load file. class langchain.document_loaders.UnstructuredWordDocumentLoader(file_path: Union[str, List[str]], mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load word documents. class langchain.document_loaders.UnstructuredXMLLoader(file_path: str, mode: str = 'single', **unstructured_kwargs: Any)[source]# Loader that uses unstructured to load XML files. class langchain.document_loaders.WeatherDataLoader(client: langchain.utilities.openweathermap.OpenWeatherMapAPIWrapper, places: Sequence[str])[source]# Weather Reader. Reads the forecast & current weather of any location using OpenWeatherMap’s free API. Checkout ‘https://openweathermap.org/appid’ for more on how to generate a free OpenWeatherMap API. classmethod from_params(places: Sequence[str], *, openweathermap_api_key: Optional[str] = None) → langchain.document_loaders.weather.WeatherDataLoader[source]# lazy_load() → Iterator[langchain.schema.Document][source]# Lazily load weather data for the given locations. load() → List[langchain.schema.Document][source]# Load weather data for the given locations. class langchain.document_loaders.WebBaseLoader(web_path: Union[str, List[str]], header_template: Optional[dict] = None)[source]# Loader that uses urllib and beautiful soup to load webpages. aload() → List[langchain.schema.Document][source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-39
aload() → List[langchain.schema.Document][source]# Load text from the urls in web_path async into Documents. default_parser: str = 'html.parser'# Default parser to use for BeautifulSoup. async fetch_all(urls: List[str]) → Any[source]# Fetch all urls concurrently with rate limiting. load() → List[langchain.schema.Document][source]# Load text from the url(s) in web_path. requests_kwargs: Dict[str, Any] = {}# kwargs for requests requests_per_second: int = 2# Max number of concurrent requests to make. scrape(parser: Optional[str] = None) → Any[source]# Scrape data from webpage and return it in BeautifulSoup format. scrape_all(urls: List[str], parser: Optional[str] = None) → List[Any][source]# Fetch all urls, then return soups for all results. property web_path: str# web_paths: List[str]# class langchain.document_loaders.WhatsAppChatLoader(path: str)[source]# Loader that loads WhatsApp messages text file. load() → List[langchain.schema.Document][source]# Load documents. class langchain.document_loaders.WikipediaLoader(query: str, lang: str = 'en', load_max_docs: Optional[int] = 100, load_all_available_meta: Optional[bool] = False)[source]# Loads a query result from www.wikipedia.org into a list of Documents. The hard limit on the number of downloaded Documents is 300 for now. Each wiki page represents one Document. load() → List[langchain.schema.Document][source]# Load data into document objects.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
fe18070e4f36-40
Load data into document objects. class langchain.document_loaders.YoutubeLoader(video_id: str, add_video_info: bool = False, language: Union[str, Sequence[str]] = 'en', translation: str = 'en', continue_on_failure: bool = False)[source]# Loader that loads Youtube transcripts. static extract_video_id(youtube_url: str) → str[source]# Extract video id from common YT urls. classmethod from_youtube_url(youtube_url: str, **kwargs: Any) → langchain.document_loaders.youtube.YoutubeLoader[source]# Given youtube URL, load video. load() → List[langchain.schema.Document][source]# Load documents. previous Text Splitter next Vector Stores By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/document_loaders.html
0efe78fd32e2-0
.rst .pdf SerpAPI SerpAPI# For backwards compatiblity. pydantic model langchain.serpapi.SerpAPIWrapper[source]# Wrapper around SerpAPI. To use, you should have the google-search-results python package installed, and the environment variable SERPAPI_API_KEY set with your API key, or pass serpapi_api_key as a named parameter to the constructor. Example from langchain import SerpAPIWrapper serpapi = SerpAPIWrapper() field aiosession: Optional[aiohttp.client.ClientSession] = None# field params: dict = {'engine': 'google', 'gl': 'us', 'google_domain': 'google.com', 'hl': 'en'}# field serpapi_api_key: Optional[str] = None# async aresults(query: str) → dict[source]# Use aiohttp to run query through SerpAPI and return the results async. async arun(query: str, **kwargs: Any) → str[source]# Run query through SerpAPI and parse result async. get_params(query: str) → Dict[str, str][source]# Get parameters for SerpAPI. results(query: str) → dict[source]# Run query through SerpAPI and return the raw result. run(query: str, **kwargs: Any) → str[source]# Run query through SerpAPI and parse result. By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/serpapi.html
6d5c37c1dbcb-0
.rst .pdf Vector Stores Vector Stores# Wrappers on top of vector stores. class langchain.vectorstores.AnalyticDB(connection_string: str, embedding_function: langchain.embeddings.base.Embeddings, collection_name: str = 'langchain', collection_metadata: Optional[dict] = None, pre_delete_collection: bool = False, logger: Optional[logging.Logger] = None)[source]# VectorStore implementation using AnalyticDB. AnalyticDB is a distributed full PostgresSQL syntax cloud-native database. - connection_string is a postgres connection string. - embedding_function any embedding function implementing langchain.embeddings.base.Embeddings interface. collection_name is the name of the collection to use. (default: langchain) NOTE: This is not the name of the table, but the name of the collection.The tables will be created when initializing the store (if not exists) So, make sure the user has the right permissions to create tables. pre_delete_collection if True, will delete the collection if it exists.(default: False) - Useful for testing. add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. kwargs – vectorstore specific parameters Returns List of ids from adding the texts into the vectorstore. connect() → sqlalchemy.engine.base.Connection[source]# classmethod connection_string_from_db_params(driver: str, host: str, port: int, database: str, user: str, password: str) → str[source]# Return connection string from database parameters.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-1
Return connection string from database parameters. create_collection() → None[source]# create_tables_if_not_exists() → None[source]# delete_collection() → None[source]# drop_tables() → None[source]# classmethod from_documents(documents: List[langchain.schema.Document], embedding: langchain.embeddings.base.Embeddings, collection_name: str = 'langchain', ids: Optional[List[str]] = None, pre_delete_collection: bool = False, **kwargs: Any) → langchain.vectorstores.analyticdb.AnalyticDB[source]# Return VectorStore initialized from documents and embeddings. Postgres connection string is required Either pass it as a parameter or set the PGVECTOR_CONNECTION_STRING environment variable. classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, collection_name: str = 'langchain', ids: Optional[List[str]] = None, pre_delete_collection: bool = False, **kwargs: Any) → langchain.vectorstores.analyticdb.AnalyticDB[source]# Return VectorStore initialized from texts and embeddings. Postgres connection string is required Either pass it as a parameter or set the PGVECTOR_CONNECTION_STRING environment variable. get_collection(session: sqlalchemy.orm.session.Session) → Optional[langchain.vectorstores.analyticdb.CollectionStore][source]# classmethod get_connection_string(kwargs: Dict[str, Any]) → str[source]# similarity_search(query: str, k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Run similarity search with AnalyticDB with distance. Parameters query (str) – Query text to search for. k (int) – Number of results to return. Defaults to 4.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-2
k (int) – Number of results to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents most similar to the query. similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents most similar to the query vector. similarity_search_with_score(query: str, k: int = 4, filter: Optional[dict] = None) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents most similar to the query and score for each similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None) → List[Tuple[langchain.schema.Document, float]][source]# class langchain.vectorstores.Annoy(embedding_function: Callable, index: Any, metric: str, docstore: langchain.docstore.base.Docstore, index_to_docstore_id: Dict[int, str])[source]# Wrapper around Annoy vector database. To use, you should have the annoy python package installed. Example from langchain import Annoy
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-3
Example from langchain import Annoy db = Annoy(embedding_function, index, docstore, index_to_docstore_id) add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. kwargs – vectorstore specific parameters Returns List of ids from adding the texts into the vectorstore. classmethod from_embeddings(text_embeddings: List[Tuple[str, List[float]]], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, metric: str = 'angular', trees: int = 100, n_jobs: int = - 1, **kwargs: Any) → langchain.vectorstores.annoy.Annoy[source]# Construct Annoy wrapper from embeddings. Parameters text_embeddings – List of tuples of (text, embedding) embedding – Embedding function to use. metadatas – List of metadata dictionaries to associate with documents. metric – Metric to use for indexing. Defaults to “angular”. trees – Number of trees to use for indexing. Defaults to 100. n_jobs – Number of jobs to use for indexing. Defaults to -1 This is a user friendly interface that: Creates an in memory docstore with provided embeddings Initializes the Annoy database This is intended to be a quick way to get started. Example from langchain import Annoy from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() text_embeddings = embeddings.embed_documents(texts) text_embedding_pairs = list(zip(texts, text_embeddings))
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-4
text_embedding_pairs = list(zip(texts, text_embeddings)) db = Annoy.from_embeddings(text_embedding_pairs, embeddings) classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, metric: str = 'angular', trees: int = 100, n_jobs: int = - 1, **kwargs: Any) → langchain.vectorstores.annoy.Annoy[source]# Construct Annoy wrapper from raw documents. Parameters texts – List of documents to index. embedding – Embedding function to use. metadatas – List of metadata dictionaries to associate with documents. metric – Metric to use for indexing. Defaults to “angular”. trees – Number of trees to use for indexing. Defaults to 100. n_jobs – Number of jobs to use for indexing. Defaults to -1. This is a user friendly interface that: Embeds documents. Creates an in memory docstore Initializes the Annoy database This is intended to be a quick way to get started. Example from langchain import Annoy from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() index = Annoy.from_texts(texts, embeddings) classmethod load_local(folder_path: str, embeddings: langchain.embeddings.base.Embeddings) → langchain.vectorstores.annoy.Annoy[source]# Load Annoy index, docstore, and index_to_docstore_id to disk. Parameters folder_path – folder path to load index, docstore, and index_to_docstore_id from. embeddings – Embeddings to use when generating queries.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-5
embeddings – Embeddings to use when generating queries. max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. fetch_k – Number of Documents to fetch to pass to MMR algorithm. k – Number of Documents to return. Defaults to 4. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-6
Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. process_index_results(idxs: List[int], dists: List[float]) → List[Tuple[langchain.schema.Document, float]][source]# Turns annoy results into a list of documents and scores. Parameters idxs – List of indices of the documents in the index. dists – List of distances of the documents in the index. Returns List of Documents and scores. save_local(folder_path: str, prefault: bool = False) → None[source]# Save Annoy index, docstore, and index_to_docstore_id to disk. Parameters folder_path – folder path to save index, docstore, and index_to_docstore_id to. prefault – Whether to pre-load the index into memory. similarity_search(query: str, k: int = 4, search_k: int = - 1, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. search_k – inspect up to search_k nodes which defaults to n_trees * n if not provided Returns List of Documents most similar to the query. similarity_search_by_index(docstore_index: int, k: int = 4, search_k: int = - 1, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to docstore_index. Parameters docstore_index – Index of document in docstore k – Number of Documents to return. Defaults to 4. search_k – inspect up to search_k nodes which defaults to n_trees * n if not provided Returns
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-7
to n_trees * n if not provided Returns List of Documents most similar to the embedding. similarity_search_by_vector(embedding: List[float], k: int = 4, search_k: int = - 1, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. search_k – inspect up to search_k nodes which defaults to n_trees * n if not provided Returns List of Documents most similar to the embedding. similarity_search_with_score(query: str, k: int = 4, search_k: int = - 1) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. search_k – inspect up to search_k nodes which defaults to n_trees * n if not provided Returns List of Documents most similar to the query and score for each similarity_search_with_score_by_index(docstore_index: int, k: int = 4, search_k: int = - 1) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. search_k – inspect up to search_k nodes which defaults to n_trees * n if not provided Returns List of Documents most similar to the query and score for each
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-8
Returns List of Documents most similar to the query and score for each similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, search_k: int = - 1) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. search_k – inspect up to search_k nodes which defaults to n_trees * n if not provided Returns List of Documents most similar to the query and score for each class langchain.vectorstores.AtlasDB(name: str, embedding_function: Optional[langchain.embeddings.base.Embeddings] = None, api_key: Optional[str] = None, description: str = 'A description for your project', is_public: bool = True, reset_project_if_exists: bool = False)[source]# Wrapper around Atlas: Nomic’s neural database and rhizomatic instrument. To use, you should have the nomic python package installed. Example from langchain.vectorstores import AtlasDB from langchain.embeddings.openai import OpenAIEmbeddings embeddings = OpenAIEmbeddings() vectorstore = AtlasDB("my_project", embeddings.embed_query) add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, refresh: bool = True, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts (Iterable[str]) – Texts to add to the vectorstore. metadatas (Optional[List[dict]], optional) – Optional list of metadatas. ids (Optional[List[str]]) – An optional list of ids.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-9
ids (Optional[List[str]]) – An optional list of ids. refresh (bool) – Whether or not to refresh indices with the updated data. Default True. Returns List of IDs of the added texts. Return type List[str] create_index(**kwargs: Any) → Any[source]# Creates an index in your project. See https://docs.nomic.ai/atlas_api.html#nomic.project.AtlasProject.create_index for full detail. classmethod from_documents(documents: List[langchain.schema.Document], embedding: Optional[langchain.embeddings.base.Embeddings] = None, ids: Optional[List[str]] = None, name: Optional[str] = None, api_key: Optional[str] = None, persist_directory: Optional[str] = None, description: str = 'A description for your project', is_public: bool = True, reset_project_if_exists: bool = False, index_kwargs: Optional[dict] = None, **kwargs: Any) → langchain.vectorstores.atlas.AtlasDB[source]# Create an AtlasDB vectorstore from a list of documents. Parameters name (str) – Name of the collection to create. api_key (str) – Your nomic API key, documents (List[Document]) – List of documents to add to the vectorstore. embedding (Optional[Embeddings]) – Embedding function. Defaults to None. ids (Optional[List[str]]) – Optional list of document IDs. If None, ids will be auto created description (str) – A description for your project. is_public (bool) – Whether your project is publicly accessible. True by default. reset_project_if_exists (bool) – Whether to reset this project if it already exists. Default False. Generally userful during development and testing. index_kwargs (Optional[dict]) – Dict of kwargs for index creation.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-10
index_kwargs (Optional[dict]) – Dict of kwargs for index creation. See https://docs.nomic.ai/atlas_api.html Returns Nomic’s neural database and finest rhizomatic instrument Return type AtlasDB classmethod from_texts(texts: List[str], embedding: Optional[langchain.embeddings.base.Embeddings] = None, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, name: Optional[str] = None, api_key: Optional[str] = None, description: str = 'A description for your project', is_public: bool = True, reset_project_if_exists: bool = False, index_kwargs: Optional[dict] = None, **kwargs: Any) → langchain.vectorstores.atlas.AtlasDB[source]# Create an AtlasDB vectorstore from a raw documents. Parameters texts (List[str]) – The list of texts to ingest. name (str) – Name of the project to create. api_key (str) – Your nomic API key, embedding (Optional[Embeddings]) – Embedding function. Defaults to None. metadatas (Optional[List[dict]]) – List of metadatas. Defaults to None. ids (Optional[List[str]]) – Optional list of document IDs. If None, ids will be auto created description (str) – A description for your project. is_public (bool) – Whether your project is publicly accessible. True by default. reset_project_if_exists (bool) – Whether to reset this project if it already exists. Default False. Generally userful during development and testing. index_kwargs (Optional[dict]) – Dict of kwargs for index creation. See https://docs.nomic.ai/atlas_api.html Returns Nomic’s neural database and finest rhizomatic instrument Return type AtlasDB
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-11
Returns Nomic’s neural database and finest rhizomatic instrument Return type AtlasDB similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Run similarity search with AtlasDB Parameters query (str) – Query text to search for. k (int) – Number of results to return. Defaults to 4. Returns List of documents most similar to the query text. Return type List[Document] class langchain.vectorstores.AwaDB(table_name: str = 'langchain_awadb', embedding_model: Optional[Embeddings] = None, log_and_data_dir: Optional[str] = None, client: Optional[awadb.Client] = None)[source]# Interface implemented by AwaDB vector stores. add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. :param texts: Iterable of strings to add to the vectorstore. :param metadatas: Optional list of metadatas associated with the texts. :param kwargs: vectorstore specific parameters Returns List of ids from adding the texts into the vectorstore. classmethod from_documents(documents: List[Document], embedding: Optional[Embeddings] = None, table_name: str = 'langchain_awadb', logging_and_data_dir: Optional[str] = None, client: Optional[awadb.Client] = None, **kwargs: Any) → AwaDB[source]# Create an AwaDB vectorstore from a list of documents. If a logging_and_data_dir specified, the table will be persisted there. Parameters documents (List[Document]) – List of documents to add to the vectorstore.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-12
Parameters documents (List[Document]) – List of documents to add to the vectorstore. embedding (Optional[Embeddings]) – Embedding function. Defaults to None. table_name (str) – Name of the collection to create. logging_and_data_dir (Optional[str]) – Directory to persist the table. client (Optional[awadb.Client]) – AwaDB client Returns AwaDB vectorstore. Return type AwaDB classmethod from_texts(texts: List[str], embedding: Optional[Embeddings] = None, metadatas: Optional[List[dict]] = None, table_name: str = 'langchain_awadb', logging_and_data_dir: Optional[str] = None, client: Optional[awadb.Client] = None, **kwargs: Any) → AwaDB[source]# Create an AwaDB vectorstore from a raw documents. Parameters texts (List[str]) – List of texts to add to the table. embedding (Optional[Embeddings]) – Embedding function. Defaults to None. metadatas (Optional[List[dict]]) – List of metadatas. Defaults to None. table_name (str) – Name of the table to create. logging_and_data_dir (Optional[str]) – Directory of logging and persistence. client (Optional[awadb.Client]) – AwaDB client Returns AwaDB vectorstore. Return type AwaDB load_local(table_name: str = 'langchain_awadb', **kwargs: Any) → bool[source]# similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to query.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-13
Return docs most similar to query. similarity_search_by_vector(embedding: Optional[List[float]] = None, k: int = 4, scores: Optional[list] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query vector. similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[langchain.schema.Document, float]][source]# Return docs and relevance scores, normalized on a scale from 0 to 1. 0 is dissimilar, 1 is most similar. similarity_search_with_score(query: str, k: int = 4, **kwargs: Any) → List[Tuple[langchain.schema.Document, float]][source]# Return docs and relevance scores, normalized on a scale from 0 to 1. 0 is dissimilar, 1 is most similar. class langchain.vectorstores.AzureSearch(azure_search_endpoint: str, azure_search_key: str, index_name: str, embedding_function: Callable, search_type: str = 'hybrid', semantic_configuration_name: Optional[str] = None, semantic_query_language: str = 'en-us', **kwargs: Any)[source]# add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str][source]# Add texts data to an existing index.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-14
Add texts data to an existing index. classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, azure_search_endpoint: str = '', azure_search_key: str = '', index_name: str = 'langchain-index', **kwargs: Any) → langchain.vectorstores.azuresearch.AzureSearch[source]# Return VectorStore initialized from texts and embeddings. hybrid_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Returns the most similar indexed documents to the query text. Parameters query (str) – The query text for which to find similar documents. k (int) – The number of documents to return. Default is 4. Returns A list of documents that are most similar to the query text. Return type List[Document] hybrid_search_with_score(query: str, k: int = 4, filters: Optional[str] = None) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query with an hybrid query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query and score for each semantic_hybrid_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Returns the most similar indexed documents to the query text. Parameters query (str) – The query text for which to find similar documents. k (int) – The number of documents to return. Default is 4. Returns A list of documents that are most similar to the query text. Return type List[Document]
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-15
Return type List[Document] semantic_hybrid_search_with_score(query: str, k: int = 4, filters: Optional[str] = None) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query with an hybrid query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query and score for each similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to query. vector_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Returns the most similar indexed documents to the query text. Parameters query (str) – The query text for which to find similar documents. k (int) – The number of documents to return. Default is 4. Returns A list of documents that are most similar to the query text. Return type List[Document] vector_search_with_score(query: str, k: int = 4, filters: Optional[str] = None) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query and score for each
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-16
Returns List of Documents most similar to the query and score for each class langchain.vectorstores.Chroma(collection_name: str = 'langchain', embedding_function: Optional[Embeddings] = None, persist_directory: Optional[str] = None, client_settings: Optional[chromadb.config.Settings] = None, collection_metadata: Optional[Dict] = None, client: Optional[chromadb.Client] = None)[source]# Wrapper around ChromaDB embeddings platform. To use, you should have the chromadb python package installed. Example from langchain.vectorstores import Chroma from langchain.embeddings.openai import OpenAIEmbeddings embeddings = OpenAIEmbeddings() vectorstore = Chroma("langchain_store", embeddings) add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts (Iterable[str]) – Texts to add to the vectorstore. metadatas (Optional[List[dict]], optional) – Optional list of metadatas. ids (Optional[List[str]], optional) – Optional list of IDs. Returns List of IDs of the added texts. Return type List[str] delete_collection() → None[source]# Delete the collection. classmethod from_documents(documents: List[Document], embedding: Optional[Embeddings] = None, ids: Optional[List[str]] = None, collection_name: str = 'langchain', persist_directory: Optional[str] = None, client_settings: Optional[chromadb.config.Settings] = None, client: Optional[chromadb.Client] = None, **kwargs: Any) → Chroma[source]# Create a Chroma vectorstore from a list of documents.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-17
Create a Chroma vectorstore from a list of documents. If a persist_directory is specified, the collection will be persisted there. Otherwise, the data will be ephemeral in-memory. Parameters collection_name (str) – Name of the collection to create. persist_directory (Optional[str]) – Directory to persist the collection. ids (Optional[List[str]]) – List of document IDs. Defaults to None. documents (List[Document]) – List of documents to add to the vectorstore. embedding (Optional[Embeddings]) – Embedding function. Defaults to None. client_settings (Optional[chromadb.config.Settings]) – Chroma client settings Returns Chroma vectorstore. Return type Chroma classmethod from_texts(texts: List[str], embedding: Optional[Embeddings] = None, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, collection_name: str = 'langchain', persist_directory: Optional[str] = None, client_settings: Optional[chromadb.config.Settings] = None, client: Optional[chromadb.Client] = None, **kwargs: Any) → Chroma[source]# Create a Chroma vectorstore from a raw documents. If a persist_directory is specified, the collection will be persisted there. Otherwise, the data will be ephemeral in-memory. Parameters texts (List[str]) – List of texts to add to the collection. collection_name (str) – Name of the collection to create. persist_directory (Optional[str]) – Directory to persist the collection. embedding (Optional[Embeddings]) – Embedding function. Defaults to None. metadatas (Optional[List[dict]]) – List of metadatas. Defaults to None. ids (Optional[List[str]]) – List of document IDs. Defaults to None.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-18
ids (Optional[List[str]]) – List of document IDs. Defaults to None. client_settings (Optional[chromadb.config.Settings]) – Chroma client settings Returns Chroma vectorstore. Return type Chroma get(include: Optional[List[str]] = None) → Dict[str, Any][source]# Gets the collection. Parameters include (Optional[List[str]]) – List of fields to include from db. Defaults to None. max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, str]] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, str]] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-19
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents selected by maximal marginal relevance. persist() → None[source]# Persist the collection. This can be used to explicitly persist the data to disk. It will also be called automatically when the object is destroyed. similarity_search(query: str, k: int = 4, filter: Optional[Dict[str, str]] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Run similarity search with Chroma. Parameters query (str) – Query text to search for. k (int) – Number of results to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of documents most similar to the query text. Return type List[Document] similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[Dict[str, str]] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to embedding vector. :param embedding: Embedding to look up documents similar to. :type embedding: str :param k: Number of Documents to return. Defaults to 4. :type k: int
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-20
:param k: Number of Documents to return. Defaults to 4. :type k: int :param filter: Filter by metadata. Defaults to None. :type filter: Optional[Dict[str, str]] Returns List of Documents most similar to the query vector. similarity_search_with_score(query: str, k: int = 4, filter: Optional[Dict[str, str]] = None, **kwargs: Any) → List[Tuple[langchain.schema.Document, float]][source]# Run similarity search with Chroma with distance. Parameters query (str) – Query text to search for. k (int) – Number of results to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of documents most similar to the query text and cosine distance in float for each. Lower score represents more similarity. Return type List[Tuple[Document, float]] update_document(document_id: str, document: langchain.schema.Document) → None[source]# Update a document in the collection. Parameters document_id (str) – ID of the document to update. document (Document) – Document to update. class langchain.vectorstores.Clickhouse(embedding: langchain.embeddings.base.Embeddings, config: Optional[langchain.vectorstores.clickhouse.ClickhouseSettings] = None, **kwargs: Any)[source]# Wrapper around ClickHouse vector database You need a clickhouse-connect python package, and a valid account to connect to ClickHouse. ClickHouse can not only search with simple vector indexes, it also supports complex query with multiple conditions, constraints and even sub-queries. For more information, please visit[ClickHouse official site](https://clickhouse.com/clickhouse)
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-21
add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, batch_size: int = 32, ids: Optional[Iterable[str]] = None, **kwargs: Any) → List[str][source]# Insert more texts through the embeddings and add to the VectorStore. Parameters texts – Iterable of strings to add to the VectorStore. ids – Optional list of ids to associate with the texts. batch_size – Batch size of insertion metadata – Optional column data to be inserted Returns List of ids from adding the texts into the VectorStore. drop() → None[source]# Helper function: Drop data escape_str(value: str) → str[source]# classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[Dict[Any, Any]]] = None, config: Optional[langchain.vectorstores.clickhouse.ClickhouseSettings] = None, text_ids: Optional[Iterable[str]] = None, batch_size: int = 32, **kwargs: Any) → langchain.vectorstores.clickhouse.Clickhouse[source]# Create ClickHouse wrapper with existing texts Parameters embedding_function (Embeddings) – Function to extract text embedding texts (Iterable[str]) – List or tuple of strings to be added config (ClickHouseSettings, Optional) – ClickHouse configuration text_ids (Optional[Iterable], optional) – IDs for the texts. Defaults to None. batch_size (int, optional) – Batchsize when transmitting data to ClickHouse. Defaults to 32. metadata (List[dict], optional) – metadata to texts. Defaults to None. into (Other keyword arguments will pass) – [clickhouse-connect](https://clickhouse.com/docs/en/integrations/python#clickhouse-connect-driver-api) Returns ClickHouse Index property metadata_column: str#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-22
Returns ClickHouse Index property metadata_column: str# similarity_search(query: str, k: int = 4, where_str: Optional[str] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Perform a similarity search with ClickHouse Parameters query (str) – query string k (int, optional) – Top K neighbors to retrieve. Defaults to 4. where_str (Optional[str], optional) – where condition string. Defaults to None. NOTE – Please do not let end-user to fill this and always be aware of SQL injection. When dealing with metadatas, remember to use {self.metadata_column}.attribute instead of attribute alone. The default name for it is metadata. Returns List of Documents Return type List[Document] similarity_search_by_vector(embedding: List[float], k: int = 4, where_str: Optional[str] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Perform a similarity search with ClickHouse by vectors Parameters query (str) – query string k (int, optional) – Top K neighbors to retrieve. Defaults to 4. where_str (Optional[str], optional) – where condition string. Defaults to None. NOTE – Please do not let end-user to fill this and always be aware of SQL injection. When dealing with metadatas, remember to use {self.metadata_column}.attribute instead of attribute alone. The default name for it is metadata. Returns List of (Document, similarity) Return type List[Document] similarity_search_with_relevance_scores(query: str, k: int = 4, where_str: Optional[str] = None, **kwargs: Any) → List[Tuple[langchain.schema.Document, float]][source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-23
Perform a similarity search with ClickHouse Parameters query (str) – query string k (int, optional) – Top K neighbors to retrieve. Defaults to 4. where_str (Optional[str], optional) – where condition string. Defaults to None. NOTE – Please do not let end-user to fill this and always be aware of SQL injection. When dealing with metadatas, remember to use {self.metadata_column}.attribute instead of attribute alone. The default name for it is metadata. Returns List of documents Return type List[Document] pydantic settings langchain.vectorstores.ClickhouseSettings[source]# ClickHouse Client Configuration Attribute: clickhouse_host (str)An URL to connect to MyScale backend.Defaults to ‘localhost’. clickhouse_port (int) : URL port to connect with HTTP. Defaults to 8443. username (str) : Username to login. Defaults to None. password (str) : Password to login. Defaults to None. index_type (str): index type string. index_param (list): index build parameter. index_query_params(dict): index query parameters. database (str) : Database name to find the table. Defaults to ‘default’. table (str) : Table name to operate on. Defaults to ‘vector_table’. metric (str)Metric to compute distance,supported are (‘angular’, ‘euclidean’, ‘manhattan’, ‘hamming’, ‘dot’). Defaults to ‘angular’. spotify/annoy column_map (Dict)Column type map to project column name onto langchainsemantics. Must have keys: text, id, vector, must be same size to number of columns. For example: .. code-block:: python {‘id’: ‘text_id’, ‘uuid’: ‘global_unique_id’ ‘embedding’: ‘text_embedding’,
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-24
‘uuid’: ‘global_unique_id’ ‘embedding’: ‘text_embedding’, ‘document’: ‘text_plain’, ‘metadata’: ‘metadata_dictionary_in_json’, } Defaults to identity map. Show JSON schema{ "title": "ClickhouseSettings",
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-25
Show JSON schema{ "title": "ClickhouseSettings", "description": "ClickHouse Client Configuration\n\nAttribute:\n clickhouse_host (str) : An URL to connect to MyScale backend.\n Defaults to 'localhost'.\n clickhouse_port (int) : URL port to connect with HTTP. Defaults to 8443.\n username (str) : Username to login. Defaults to None.\n password (str) : Password to login. Defaults to None.\n index_type (str): index type string.\n index_param (list): index build parameter.\n index_query_params(dict): index query parameters.\n database (str) : Database name to find the table. Defaults to 'default'.\n table (str) : Table name to operate on.\n Defaults to 'vector_table'.\n metric (str) : Metric to compute distance,\n supported are ('angular', 'euclidean', 'manhattan', 'hamming',\n 'dot'). Defaults to 'angular'.\n https://github.com/spotify/annoy/blob/main/src/annoymodule.cc#L149-L169\n\n column_map (Dict) : Column type map to project column name onto langchain\n semantics. Must have keys: `text`, `id`, `vector`,\n must be same size to number of columns. For example:\n .. code-block:: python\n\n {\n 'id': 'text_id',\n 'uuid': 'global_unique_id'\n 'embedding': 'text_embedding',\n 'document': 'text_plain',\n 'metadata': 'metadata_dictionary_in_json',\n }\n\n Defaults to identity map.", "type": "object", "properties": { "host": {
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-26
"type": "object", "properties": { "host": { "title": "Host", "default": "localhost", "env_names": "{'clickhouse_host'}", "type": "string" }, "port": { "title": "Port", "default": 8123, "env_names": "{'clickhouse_port'}", "type": "integer" }, "username": { "title": "Username", "env_names": "{'clickhouse_username'}", "type": "string" }, "password": { "title": "Password", "env_names": "{'clickhouse_password'}", "type": "string" }, "index_type": { "title": "Index Type", "default": "annoy", "env_names": "{'clickhouse_index_type'}", "type": "string" }, "index_param": { "title": "Index Param", "default": [ 100, "'L2Distance'" ], "env_names": "{'clickhouse_index_param'}", "anyOf": [ { "type": "array", "items": {} }, { "type": "object" } ] }, "index_query_params": { "title": "Index Query Params", "default": {}, "env_names": "{'clickhouse_index_query_params'}", "type": "object", "additionalProperties": { "type": "string" } },
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-27
"type": "string" } }, "column_map": { "title": "Column Map", "default": { "id": "id", "uuid": "uuid", "document": "document", "embedding": "embedding", "metadata": "metadata" }, "env_names": "{'clickhouse_column_map'}", "type": "object", "additionalProperties": { "type": "string" } }, "database": { "title": "Database", "default": "default", "env_names": "{'clickhouse_database'}", "type": "string" }, "table": { "title": "Table", "default": "langchain", "env_names": "{'clickhouse_table'}", "type": "string" }, "metric": { "title": "Metric", "default": "angular", "env_names": "{'clickhouse_metric'}", "type": "string" } }, "additionalProperties": false } Config env_file: str = .env env_file_encoding: str = utf-8 env_prefix: str = clickhouse_ Fields column_map (Dict[str, str]) database (str) host (str) index_param (Optional[Union[List, Dict]]) index_query_params (Dict[str, str]) index_type (str) metric (str) password (Optional[str]) port (int) table (str) username (Optional[str])
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-28
port (int) table (str) username (Optional[str]) field column_map: Dict[str, str] = {'document': 'document', 'embedding': 'embedding', 'id': 'id', 'metadata': 'metadata', 'uuid': 'uuid'}# field database: str = 'default'# field host: str = 'localhost'# field index_param: Optional[Union[List, Dict]] = [100, "'L2Distance'"]# field index_query_params: Dict[str, str] = {}# field index_type: str = 'annoy'# field metric: str = 'angular'# field password: Optional[str] = None# field port: int = 8123# field table: str = 'langchain'# field username: Optional[str] = None# class langchain.vectorstores.DeepLake(dataset_path: str = './deeplake/', token: Optional[str] = None, embedding_function: Optional[langchain.embeddings.base.Embeddings] = None, read_only: Optional[bool] = False, ingestion_batch_size: int = 1024, num_workers: int = 0, verbose: bool = True, **kwargs: Any)[source]# Wrapper around Deep Lake, a data lake for deep learning applications. We implement naive similarity search and filtering for fast prototyping, but it can be extended with Tensor Query Language (TQL) for production use cases over billion rows. Why Deep Lake? Not only stores embeddings, but also the original data with version control. Serverless, doesn’t require another service and can be used with majorcloud providers (S3, GCS, etc.) More than just a multi-modal vector store. You can use the datasetto fine-tune your own LLM models. To use, you should have the deeplake python package installed. Example
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-29
To use, you should have the deeplake python package installed. Example from langchain.vectorstores import DeepLake from langchain.embeddings.openai import OpenAIEmbeddings embeddings = OpenAIEmbeddings() vectorstore = DeepLake("langchain_store", embeddings.embed_query) add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts (Iterable[str]) – Texts to add to the vectorstore. metadatas (Optional[List[dict]], optional) – Optional list of metadatas. ids (Optional[List[str]], optional) – Optional list of IDs. Returns List of IDs of the added texts. Return type List[str] delete(ids: Any[List[str], None] = None, filter: Any[Dict[str, str], None] = None, delete_all: Any[bool, None] = None) → bool[source]# Delete the entities in the dataset Parameters ids (Optional[List[str]], optional) – The document_ids to delete. Defaults to None. filter (Optional[Dict[str, str]], optional) – The filter to delete by. Defaults to None. delete_all (Optional[bool], optional) – Whether to drop the dataset. Defaults to None. delete_dataset() → None[source]# Delete the collection. classmethod force_delete_by_path(path: str) → None[source]# Force delete dataset by path
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-30
Force delete dataset by path classmethod from_texts(texts: List[str], embedding: Optional[langchain.embeddings.base.Embeddings] = None, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, dataset_path: str = './deeplake/', **kwargs: Any) → langchain.vectorstores.deeplake.DeepLake[source]# Create a Deep Lake dataset from a raw documents. If a dataset_path is specified, the dataset will be persisted in that location, otherwise by default at ./deeplake Parameters path (str, pathlib.Path) – The full path to the dataset. Can be: Deep Lake cloud path of the form hub://username/dataset_name.To write to Deep Lake cloud datasets, ensure that you are logged in to Deep Lake (use ‘activeloop login’ from command line) AWS S3 path of the form s3://bucketname/path/to/dataset.Credentials are required in either the environment Google Cloud Storage path of the formgcs://bucketname/path/to/dataset Credentials are required in either the environment Local file system path of the form ./path/to/dataset or~/path/to/dataset or path/to/dataset. In-memory path of the form mem://path/to/dataset which doesn’tsave the dataset, but keeps it in memory instead. Should be used only for testing as it does not persist. documents (List[Document]) – List of documents to add. embedding (Optional[Embeddings]) – Embedding function. Defaults to None. metadatas (Optional[List[dict]]) – List of metadatas. Defaults to None. ids (Optional[List[str]]) – List of document IDs. Defaults to None. Returns Deep Lake dataset. Return type DeepLake
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-31
Returns Deep Lake dataset. Return type DeepLake max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param query: Text to look up documents similar to. :param k: Number of Documents to return. Defaults to 4. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm. :param lambda_mult: Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. persist() → None[source]# Persist the collection.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-32
persist() → None[source]# Persist the collection. similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to query. Parameters query – text to embed and run the query on. k – Number of Documents to return. Defaults to 4. query – Text to look up documents similar to. embedding – Embedding function to use. Defaults to None. k – Number of Documents to return. Defaults to 4. distance_metric – L2 for Euclidean, L1 for Nuclear, max L-infinity distance, cos for cosine similarity, ‘dot’ for dot product Defaults to L2. filter – Attribute filter by metadata example {‘key’: ‘value’}. Defaults to None. maximal_marginal_relevance – Whether to use maximal marginal relevance. Defaults to False. fetch_k – Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. return_score – Whether to return the score. Defaults to False. Returns List of Documents most similar to the query vector. similarity_search_by_vector(embedding: List[float], k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query vector. similarity_search_with_score(query: str, distance_metric: str = 'L2', k: int = 4, filter: Optional[Dict[str, str]] = None) → List[Tuple[langchain.schema.Document, float]][source]# Run similarity search with Deep Lake with distance returned.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-33
Run similarity search with Deep Lake with distance returned. Parameters query (str) – Query text to search for. distance_metric – L2 for Euclidean, L1 for Nuclear, max L-infinity distance, cos for cosine similarity, ‘dot’ for dot product. Defaults to L2. k (int) – Number of results to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of documents most similar to the querytext with distance in float. Return type List[Tuple[Document, float]] class langchain.vectorstores.DocArrayHnswSearch(doc_index: BaseDocIndex, embedding: langchain.embeddings.base.Embeddings)[source]# Wrapper around HnswLib storage. To use it, you should have the docarray package with version >=0.32.0 installed. You can install it with pip install “langchain[docarray]”. classmethod from_params(embedding: langchain.embeddings.base.Embeddings, work_dir: str, n_dim: int, dist_metric: Literal['cosine', 'ip', 'l2'] = 'cosine', max_elements: int = 1024, index: bool = True, ef_construction: int = 200, ef: int = 10, M: int = 16, allow_replace_deleted: bool = True, num_threads: int = 1, **kwargs: Any) → langchain.vectorstores.docarray.hnsw.DocArrayHnswSearch[source]# Initialize DocArrayHnswSearch store. Parameters embedding (Embeddings) – Embedding function. work_dir (str) – path to the location where all the data will be stored. n_dim (int) – dimension of an embedding.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-34
n_dim (int) – dimension of an embedding. dist_metric (str) – Distance metric for DocArrayHnswSearch can be one of: “cosine”, “ip”, and “l2”. Defaults to “cosine”. max_elements (int) – Maximum number of vectors that can be stored. Defaults to 1024. index (bool) – Whether an index should be built for this field. Defaults to True. ef_construction (int) – defines a construction time/accuracy trade-off. Defaults to 200. ef (int) – parameter controlling query time/accuracy trade-off. Defaults to 10. M (int) – parameter that defines the maximum number of outgoing connections in the graph. Defaults to 16. allow_replace_deleted (bool) – Enables replacing of deleted elements with new added ones. Defaults to True. num_threads (int) – Sets the number of cpu threads to use. Defaults to 1. **kwargs – Other keyword arguments to be passed to the get_doc_cls method. classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, work_dir: Optional[str] = None, n_dim: Optional[int] = None, **kwargs: Any) → langchain.vectorstores.docarray.hnsw.DocArrayHnswSearch[source]# Create an DocArrayHnswSearch store and insert data. Parameters texts (List[str]) – Text data. embedding (Embeddings) – Embedding function. metadatas (Optional[List[dict]]) – Metadata for each text if it exists. Defaults to None. work_dir (str) – path to the location where all the data will be stored. n_dim (int) – dimension of an embedding.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-35
n_dim (int) – dimension of an embedding. **kwargs – Other keyword arguments to be passed to the __init__ method. Returns DocArrayHnswSearch Vector Store class langchain.vectorstores.DocArrayInMemorySearch(doc_index: BaseDocIndex, embedding: langchain.embeddings.base.Embeddings)[source]# Wrapper around in-memory storage for exact search. To use it, you should have the docarray package with version >=0.32.0 installed. You can install it with pip install “langchain[docarray]”. classmethod from_params(embedding: langchain.embeddings.base.Embeddings, metric: Literal['cosine_sim', 'euclidian_dist', 'sgeuclidean_dist'] = 'cosine_sim', **kwargs: Any) → langchain.vectorstores.docarray.in_memory.DocArrayInMemorySearch[source]# Initialize DocArrayInMemorySearch store. Parameters embedding (Embeddings) – Embedding function. metric (str) – metric for exact nearest-neighbor search. Can be one of: “cosine_sim”, “euclidean_dist” and “sqeuclidean_dist”. Defaults to “cosine_sim”. **kwargs – Other keyword arguments to be passed to the get_doc_cls method. classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[Dict[Any, Any]]] = None, **kwargs: Any) → langchain.vectorstores.docarray.in_memory.DocArrayInMemorySearch[source]# Create an DocArrayInMemorySearch store and insert data. Parameters texts (List[str]) – Text data. embedding (Embeddings) – Embedding function. metadatas (Optional[List[Dict[Any, Any]]]) – Metadata for each text if it exists. Defaults to None.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-36
if it exists. Defaults to None. metric (str) – metric for exact nearest-neighbor search. Can be one of: “cosine_sim”, “euclidean_dist” and “sqeuclidean_dist”. Defaults to “cosine_sim”. Returns DocArrayInMemorySearch Vector Store class langchain.vectorstores.ElasticVectorSearch(elasticsearch_url: str, index_name: str, embedding: langchain.embeddings.base.Embeddings, *, ssl_verify: Optional[Dict[str, Any]] = None)[source]# Wrapper around Elasticsearch as a vector database. To connect to an Elasticsearch instance that does not require login credentials, pass the Elasticsearch URL and index name along with the embedding object to the constructor. Example from langchain import ElasticVectorSearch from langchain.embeddings import OpenAIEmbeddings embedding = OpenAIEmbeddings() elastic_vector_search = ElasticVectorSearch( elasticsearch_url="http://localhost:9200", index_name="test_index", embedding=embedding ) To connect to an Elasticsearch instance that requires login credentials, including Elastic Cloud, use the Elasticsearch URL format https://username:password@es_host:9243. For example, to connect to Elastic Cloud, create the Elasticsearch URL with the required authentication details and pass it to the ElasticVectorSearch constructor as the named parameter elasticsearch_url. You can obtain your Elastic Cloud URL and login credentials by logging in to the Elastic Cloud console at https://cloud.elastic.co, selecting your deployment, and navigating to the “Deployments” page. To obtain your Elastic Cloud password for the default “elastic” user: Log in to the Elastic Cloud console at https://cloud.elastic.co Go to “Security” > “Users” Locate the “elastic” user and click “Edit” Click “Reset password”
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-37
Locate the “elastic” user and click “Edit” Click “Reset password” Follow the prompts to reset the password The format for Elastic Cloud URLs is https://username:password@cluster_id.region_id.gcp.cloud.es.io:9243. Example from langchain import ElasticVectorSearch from langchain.embeddings import OpenAIEmbeddings embedding = OpenAIEmbeddings() elastic_host = "cluster_id.region_id.gcp.cloud.es.io" elasticsearch_url = f"https://username:password@{elastic_host}:9243" elastic_vector_search = ElasticVectorSearch( elasticsearch_url=elasticsearch_url, index_name="test_index", embedding=embedding ) Parameters elasticsearch_url (str) – The URL for the Elasticsearch instance. index_name (str) – The name of the Elasticsearch index for the embeddings. embedding (Embeddings) – An object that provides the ability to embed text. It should be an instance of a class that subclasses the Embeddings abstract base class, such as OpenAIEmbeddings() Raises ValueError – If the elasticsearch python package is not installed. add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, refresh_indices: bool = True, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. refresh_indices – bool to refresh ElasticSearch indices Returns List of ids from adding the texts into the vectorstore. client_search(client: Any, index_name: str, script_query: Dict, size: int) → Any[source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-38
create_index(client: Any, index_name: str, mapping: Dict) → None[source]# classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, elasticsearch_url: Optional[str] = None, index_name: Optional[str] = None, refresh_indices: bool = True, **kwargs: Any) → langchain.vectorstores.elastic_vector_search.ElasticVectorSearch[source]# Construct ElasticVectorSearch wrapper from raw documents. This is a user-friendly interface that: Embeds documents. Creates a new index for the embeddings in the Elasticsearch instance. Adds the documents to the newly created Elasticsearch index. This is intended to be a quick way to get started. Example from langchain import ElasticVectorSearch from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() elastic_vector_search = ElasticVectorSearch.from_texts( texts, embeddings, elasticsearch_url="http://localhost:9200" ) similarity_search(query: str, k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query. similarity_search_with_score(query: str, k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query. :param query: Text to look up documents similar to. :param k: Number of Documents to return. Defaults to 4. Returns
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-39
:param k: Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query. class langchain.vectorstores.FAISS(embedding_function: typing.Callable, index: typing.Any, docstore: langchain.docstore.base.Docstore, index_to_docstore_id: typing.Dict[int, str], relevance_score_fn: typing.Optional[typing.Callable[[float], float]] = <function _default_relevance_score_fn>, normalize_L2: bool = False)[source]# Wrapper around FAISS vector database. To use, you should have the faiss python package installed. Example from langchain import FAISS faiss = FAISS(embedding_function, index, docstore, index_to_docstore_id) add_embeddings(text_embeddings: Iterable[Tuple[str, List[float]]], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters text_embeddings – Iterable pairs of string and embedding to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. ids – Optional list of unique IDs. Returns List of ids from adding the texts into the vectorstore. add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. ids – Optional list of unique IDs. Returns List of ids from adding the texts into the vectorstore.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-40
Returns List of ids from adding the texts into the vectorstore. classmethod from_embeddings(text_embeddings: List[Tuple[str, List[float]]], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → langchain.vectorstores.faiss.FAISS[source]# Construct FAISS wrapper from raw documents. This is a user friendly interface that: Embeds documents. Creates an in memory docstore Initializes the FAISS database This is intended to be a quick way to get started. Example from langchain import FAISS from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() text_embeddings = embeddings.embed_documents(texts) text_embedding_pairs = list(zip(texts, text_embeddings)) faiss = FAISS.from_embeddings(text_embedding_pairs, embeddings) classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → langchain.vectorstores.faiss.FAISS[source]# Construct FAISS wrapper from raw documents. This is a user friendly interface that: Embeds documents. Creates an in memory docstore Initializes the FAISS database This is intended to be a quick way to get started. Example from langchain import FAISS from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() faiss = FAISS.from_texts(texts, embeddings) classmethod load_local(folder_path: str, embeddings: langchain.embeddings.base.Embeddings, index_name: str = 'index') → langchain.vectorstores.faiss.FAISS[source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-41
Load FAISS index, docstore, and index_to_docstore_id from disk. Parameters folder_path – folder path to load index, docstore, and index_to_docstore_id from. embeddings – Embeddings to use when generating queries index_name – for saving with a specific index file name max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, Any]] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch before filtering (if needed) to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, Any]] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-42
k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch before filtering to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. merge_from(target: langchain.vectorstores.faiss.FAISS) → None[source]# Merge another FAISS object with the current one. Add the target FAISS to the current one. Parameters target – FAISS object you wish to merge into the current one Returns None. save_local(folder_path: str, index_name: str = 'index') → None[source]# Save FAISS index, docstore, and index_to_docstore_id to disk. Parameters folder_path – folder path to save index, docstore, and index_to_docstore_id to. index_name – for saving with a specific index file name similarity_search(query: str, k: int = 4, filter: Optional[Dict[str, Any]] = None, fetch_k: int = 20, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter – (Optional[Dict[str, str]]): Filter by metadata. Defaults to None. fetch_k – (Optional[int]) Number of Documents to fetch before filtering. Defaults to 20. Returns List of Documents most similar to the query.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-43
Defaults to 20. Returns List of Documents most similar to the query. similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[Dict[str, Any]] = None, fetch_k: int = 20, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. fetch_k – (Optional[int]) Number of Documents to fetch before filtering. Defaults to 20. Returns List of Documents most similar to the embedding. similarity_search_with_score(query: str, k: int = 4, filter: Optional[Dict[str, Any]] = None, fetch_k: int = 20, **kwargs: Any) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. fetch_k – (Optional[int]) Number of Documents to fetch before filtering. Defaults to 20. Returns List of documents most similar to the query text with L2 distance in float. Lower score represents more similarity. similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[Dict[str, Any]] = None, fetch_k: int = 20) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query. Parameters
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-44
Return docs most similar to query. Parameters embedding – Embedding vector to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. fetch_k – (Optional[int]) Number of Documents to fetch before filtering. Defaults to 20. Returns List of documents most similar to the query text and L2 distance in float for each. Lower score represents more similarity. class langchain.vectorstores.Hologres(connection_string: str, embedding_function: langchain.embeddings.base.Embeddings, ndims: int = 1536, table_name: str = 'langchain_pg_embedding', pre_delete_table: bool = False, logger: Optional[logging.Logger] = None)[source]# VectorStore implementation using Hologres. - connection_string is a hologres connection string. - embedding_function any embedding function implementing langchain.embeddings.base.Embeddings interface. ndims is the number of dimensions of the embedding output. table_name is the name of the table to store embeddings and data.(default: langchain_pg_embedding) - NOTE: The table will be created when initializing the store (if not exists) So, make sure the user has the right permissions to create tables. pre_delete_table if True, will delete the table if it exists.(default: False) - Useful for testing. add_embeddings(texts: Iterable[str], embeddings: List[List[float]], metadatas: List[dict], ids: List[str], **kwargs: Any) → None[source]# Add embeddings to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. embeddings – List of list of embedding vectors. metadatas – List of metadatas associated with the texts. kwargs – vectorstore specific parameters
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-45
kwargs – vectorstore specific parameters add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. kwargs – vectorstore specific parameters Returns List of ids from adding the texts into the vectorstore. classmethod connection_string_from_db_params(host: str, port: int, database: str, user: str, password: str) → str[source]# Return connection string from database parameters. create_table() → None[source]# create_vector_extension() → None[source]# classmethod from_documents(documents: List[langchain.schema.Document], embedding: langchain.embeddings.base.Embeddings, ndims: int = 1536, table_name: str = 'langchain_pg_embedding', ids: Optional[List[str]] = None, pre_delete_collection: bool = False, **kwargs: Any) → langchain.vectorstores.hologres.Hologres[source]# Return VectorStore initialized from documents and embeddings. Postgres connection string is required “Either pass it as a parameter or set the HOLOGRES_CONNECTION_STRING environment variable. classmethod from_embeddings(text_embeddings: List[Tuple[str, List[float]]], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, ndims: int = 1536, table_name: str = 'langchain_pg_embedding', ids: Optional[List[str]] = None, pre_delete_table: bool = False, **kwargs: Any) → langchain.vectorstores.hologres.Hologres[source]# Construct Hologres wrapper from raw documents and pre-
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-46
Construct Hologres wrapper from raw documents and pre- generated embeddings. Return VectorStore initialized from documents and embeddings. Postgres connection string is required “Either pass it as a parameter or set the HOLOGRES_CONNECTION_STRING environment variable. Example from langchain import Hologres from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() text_embeddings = embeddings.embed_documents(texts) text_embedding_pairs = list(zip(texts, text_embeddings)) faiss = Hologres.from_embeddings(text_embedding_pairs, embeddings) classmethod from_existing_index(embedding: langchain.embeddings.base.Embeddings, ndims: int = 1536, table_name: str = 'langchain_pg_embedding', pre_delete_table: bool = False, **kwargs: Any) → langchain.vectorstores.hologres.Hologres[source]# Get intsance of an existing Hologres store.This method will return the instance of the store without inserting any new embeddings classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, ndims: int = 1536, table_name: str = 'langchain_pg_embedding', ids: Optional[List[str]] = None, pre_delete_table: bool = False, **kwargs: Any) → langchain.vectorstores.hologres.Hologres[source]# Return VectorStore initialized from texts and embeddings. Postgres connection string is required “Either pass it as a parameter or set the HOLOGRES_CONNECTION_STRING environment variable. classmethod get_connection_string(kwargs: Dict[str, Any]) → str[source]# similarity_search(query: str, k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[langchain.schema.Document][source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-47
Run similarity search with Hologres with distance. Parameters query (str) – Query text to search for. k (int) – Number of results to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents most similar to the query. similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to embedding vector. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents most similar to the query vector. similarity_search_with_score(query: str, k: int = 4, filter: Optional[dict] = None) → List[Tuple[langchain.schema.Document, float]][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter (Optional[Dict[str, str]]) – Filter by metadata. Defaults to None. Returns List of Documents most similar to the query and score for each similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[dict] = None) → List[Tuple[langchain.schema.Document, float]][source]# class langchain.vectorstores.LanceDB(connection: Any, embedding: langchain.embeddings.base.Embeddings, vector_key: Optional[str] = 'vector', id_key: Optional[str] = 'id', text_key: Optional[str] = 'text')[source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-48
Wrapper around LanceDB vector database. To use, you should have lancedb python package installed. Example db = lancedb.connect('./lancedb') table = db.open_table('my_table') vectorstore = LanceDB(table, embedding_function) vectorstore.add_texts(['text1', 'text2']) result = vectorstore.similarity_search('text1') add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any) → List[str][source]# Turn texts into embedding and add it to the database Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. ids – Optional list of ids to associate with the texts. Returns List of ids of the added texts. classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, connection: Any = None, vector_key: Optional[str] = 'vector', id_key: Optional[str] = 'id', text_key: Optional[str] = 'text', **kwargs: Any) → langchain.vectorstores.lancedb.LanceDB[source]# Return VectorStore initialized from texts and embeddings. similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Return documents most similar to the query Parameters query – String to query the vectorstore with. k – Number of documents to return. Returns List of documents most similar to the query.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-49
Returns List of documents most similar to the query. class langchain.vectorstores.MatchingEngine(project_id: str, index: MatchingEngineIndex, endpoint: MatchingEngineIndexEndpoint, embedding: Embeddings, gcs_client: storage.Client, gcs_bucket_name: str, credentials: Optional[Credentials] = None)[source]# Vertex Matching Engine implementation of the vector store. While the embeddings are stored in the Matching Engine, the embedded documents will be stored in GCS. An existing Index and corresponding Endpoint are preconditions for using this module. See usage in docs/modules/indexes/vectorstores/examples/matchingengine.ipynb Note that this implementation is mostly meant for reading if you are planning to do a real time implementation. While reading is a real time operation, updating the index takes close to one hour. add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. kwargs – vectorstore specific parameters. Returns List of ids from adding the texts into the vectorstore. classmethod from_components(project_id: str, region: str, gcs_bucket_name: str, index_id: str, endpoint_id: str, credentials_path: Optional[str] = None, embedding: Optional[langchain.embeddings.base.Embeddings] = None) → langchain.vectorstores.matching_engine.MatchingEngine[source]# Takes the object creation out of the constructor. Parameters project_id – The GCP project id. region – The default location making the API calls. It must have
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-50
region – The default location making the API calls. It must have regional. (the same location as the GCS bucket and must be) – gcs_bucket_name – The location where the vectors will be stored in created. (order for the index to be) – index_id – The id of the created index. endpoint_id – The id of the created endpoint. credentials_path – (Optional) The path of the Google credentials on system. (the local file) – embedding – The Embeddings that will be used for texts. (embedding the) – Returns A configured MatchingEngine with the texts added to the index. classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → langchain.vectorstores.matching_engine.MatchingEngine[source]# Use from components instead. similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to query. Parameters query – The string that will be used to search for similar documents. k – The amount of neighbors that will be retrieved. Returns A list of k matching documents. class langchain.vectorstores.Milvus(embedding_function: langchain.embeddings.base.Embeddings, collection_name: str = 'LangChainCollection', connection_args: Optional[dict[str, Any]] = None, consistency_level: str = 'Session', index_params: Optional[dict] = None, search_params: Optional[dict] = None, drop_old: Optional[bool] = False)[source]# Wrapper around the Milvus vector database.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-51
Wrapper around the Milvus vector database. add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, timeout: Optional[int] = None, batch_size: int = 1000, **kwargs: Any) → List[str][source]# Insert text data into Milvus. Inserting data when the collection has not be made yet will result in creating a new Collection. The data of the first entity decides the schema of the new collection, the dim is extracted from the first embedding and the columns are decided by the first metadata dict. Metada keys will need to be present for all inserted values. At the moment there is no None equivalent in Milvus. Parameters texts (Iterable[str]) – The texts to embed, it is assumed that they all fit in memory. metadatas (Optional[List[dict]]) – Metadata dicts attached to each of the texts. Defaults to None. timeout (Optional[int]) – Timeout for each batch insert. Defaults to None. batch_size (int, optional) – Batch size to use for insertion. Defaults to 1000. Raises MilvusException – Failure to add texts Returns The resulting keys for each inserted element. Return type List[str]
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-52
Returns The resulting keys for each inserted element. Return type List[str] classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, collection_name: str = 'LangChainCollection', connection_args: dict[str, Any] = {'host': 'localhost', 'password': '', 'port': '19530', 'secure': False, 'user': ''}, consistency_level: str = 'Session', index_params: Optional[dict] = None, search_params: Optional[dict] = None, drop_old: bool = False, **kwargs: Any) → langchain.vectorstores.milvus.Milvus[source]# Create a Milvus collection, indexes it with HNSW, and insert data. Parameters texts (List[str]) – Text data. embedding (Embeddings) – Embedding function. metadatas (Optional[List[dict]]) – Metadata for each text if it exists. Defaults to None. collection_name (str, optional) – Collection name to use. Defaults to “LangChainCollection”. connection_args (dict[str, Any], optional) – Connection args to use. Defaults to DEFAULT_MILVUS_CONNECTION. consistency_level (str, optional) – Which consistency level to use. Defaults to “Session”. index_params (Optional[dict], optional) – Which index_params to use. Defaults to None. search_params (Optional[dict], optional) – Which search params to use. Defaults to None. drop_old (Optional[bool], optional) – Whether to drop the collection with that name if it exists. Defaults to False. Returns Milvus Vector Store Return type Milvus
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-53
Returns Milvus Vector Store Return type Milvus max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Perform a search and return results that are reordered by MMR. Parameters query (str) – The text being searched. k (int, optional) – How many results to give. Defaults to 4. fetch_k (int, optional) – Total results to select k from. Defaults to 20. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5 param (dict, optional) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document] max_marginal_relevance_search_by_vector(embedding: list[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Perform a search and return results that are reordered by MMR. Parameters embedding (str) – The embedding vector being searched.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-54
Parameters embedding (str) – The embedding vector being searched. k (int, optional) – How many results to give. Defaults to 4. fetch_k (int, optional) – Total results to select k from. Defaults to 20. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5 param (dict, optional) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document] similarity_search(query: str, k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Perform a similarity search against the query string. Parameters query (str) – The text to search. k (int, optional) – How many results to return. Defaults to 4. param (dict, optional) – The search params for the index type. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document]
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-55
Returns Document results for search. Return type List[Document] similarity_search_by_vector(embedding: List[float], k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Perform a similarity search against the query string. Parameters embedding (List[float]) – The embedding vector to search. k (int, optional) – How many results to return. Defaults to 4. param (dict, optional) – The search params for the index type. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Document results for search. Return type List[Document] similarity_search_with_score(query: str, k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Tuple[langchain.schema.Document, float]][source]# Perform a search on a query string and return results with score. For more information about the search parameters, take a look at the pymilvus documentation found here: https://milvus.io/api-reference/pymilvus/v2.2.6/Collection/search().md Parameters query (str) – The text being searched. k (int, optional) – The amount of results ot return. Defaults to 4. param (dict) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-56
Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Return type List[float], List[Tuple[Document, any, any]] similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, param: Optional[dict] = None, expr: Optional[str] = None, timeout: Optional[int] = None, **kwargs: Any) → List[Tuple[langchain.schema.Document, float]][source]# Perform a search on a query string and return results with score. For more information about the search parameters, take a look at the pymilvus documentation found here: https://milvus.io/api-reference/pymilvus/v2.2.6/Collection/search().md Parameters embedding (List[float]) – The embedding vector being searched. k (int, optional) – The amount of results ot return. Defaults to 4. param (dict) – The search params for the specified index. Defaults to None. expr (str, optional) – Filtering expression. Defaults to None. timeout (int, optional) – How long to wait before timeout error. Defaults to None. kwargs – Collection.search() keyword arguments. Returns Result doc and score. Return type List[Tuple[Document, float]] class langchain.vectorstores.MongoDBAtlasVectorSearch(collection: Collection[MongoDBDocumentType], embedding: Embeddings, *, index_name: str = 'default', text_key: str = 'text', embedding_key: str = 'embedding')[source]# Wrapper around MongoDB Atlas Vector Search. To use, you should have both: - the pymongo python package installed
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-57
To use, you should have both: - the pymongo python package installed - a connection string associated with a MongoDB Atlas Cluster having deployed an Atlas Search index Example from langchain.vectorstores import MongoDBAtlasVectorSearch from langchain.embeddings.openai import OpenAIEmbeddings from pymongo import MongoClient mongo_client = MongoClient("<YOUR-CONNECTION-STRING>") collection = mongo_client["<db_name>"]["<collection_name>"] embeddings = OpenAIEmbeddings() vectorstore = MongoDBAtlasVectorSearch(collection, embeddings) add_texts(texts: Iterable[str], metadatas: Optional[List[Dict[str, Any]]] = None, **kwargs: Any) → List[source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. Returns List of ids from adding the texts into the vectorstore. classmethod from_connection_string(connection_string: str, namespace: str, embedding: langchain.embeddings.base.Embeddings, **kwargs: Any) → langchain.vectorstores.mongodb_atlas.MongoDBAtlasVectorSearch[source]# classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, collection: Optional[Collection[MongoDBDocumentType]] = None, **kwargs: Any) → MongoDBAtlasVectorSearch[source]# Construct MongoDBAtlasVectorSearch wrapper from raw documents. This is a user-friendly interface that: Embeds documents. Adds the documents to a provided MongoDB Atlas Vector Search index(Lucene) This is intended to be a quick way to get started. Example
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-58
This is intended to be a quick way to get started. Example similarity_search(query: str, k: int = 4, pre_filter: Optional[dict] = None, post_filter_pipeline: Optional[List[Dict]] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return MongoDB documents most similar to query. Use the knnBeta Operator available in MongoDB Atlas Search This feature is in early access and available only for evaluation purposes, to validate functionality, and to gather feedback from a small closed group of early access users. It is not recommended for production deployments as we may introduce breaking changes. For more: https://www.mongodb.com/docs/atlas/atlas-search/knn-beta Parameters query – Text to look up documents similar to. k – Optional Number of Documents to return. Defaults to 4. pre_filter – Optional Dictionary of argument(s) to prefilter on document fields. post_filter_pipeline – Optional Pipeline of MongoDB aggregation stages following the knnBeta search. Returns List of Documents most similar to the query and score for each similarity_search_with_score(query: str, *, k: int = 4, pre_filter: Optional[dict] = None, post_filter_pipeline: Optional[List[Dict]] = None) → List[Tuple[langchain.schema.Document, float]][source]# Return MongoDB documents most similar to query, along with scores. Use the knnBeta Operator available in MongoDB Atlas Search This feature is in early access and available only for evaluation purposes, to validate functionality, and to gather feedback from a small closed group of early access users. It is not recommended for production deployments as we may introduce breaking changes. For more: https://www.mongodb.com/docs/atlas/atlas-search/knn-beta Parameters query – Text to look up documents similar to.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-59
Parameters query – Text to look up documents similar to. k – Optional Number of Documents to return. Defaults to 4. pre_filter – Optional Dictionary of argument(s) to prefilter on document fields. post_filter_pipeline – Optional Pipeline of MongoDB aggregation stages following the knnBeta search. Returns List of Documents most similar to the query and score for each class langchain.vectorstores.MyScale(embedding: langchain.embeddings.base.Embeddings, config: Optional[langchain.vectorstores.myscale.MyScaleSettings] = None, **kwargs: Any)[source]# Wrapper around MyScale vector database You need a clickhouse-connect python package, and a valid account to connect to MyScale. MyScale can not only search with simple vector indexes, it also supports complex query with multiple conditions, constraints and even sub-queries. For more information, please visit[myscale official site](https://docs.myscale.com/en/overview/) add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, batch_size: int = 32, ids: Optional[Iterable[str]] = None, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. ids – Optional list of ids to associate with the texts. batch_size – Batch size of insertion metadata – Optional column data to be inserted Returns List of ids from adding the texts into the vectorstore. drop() → None[source]# Helper function: Drop data escape_str(value: str) → str[source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-60
Helper function: Drop data escape_str(value: str) → str[source]# classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[Dict[Any, Any]]] = None, config: Optional[langchain.vectorstores.myscale.MyScaleSettings] = None, text_ids: Optional[Iterable[str]] = None, batch_size: int = 32, **kwargs: Any) → langchain.vectorstores.myscale.MyScale[source]# Create Myscale wrapper with existing texts Parameters embedding_function (Embeddings) – Function to extract text embedding texts (Iterable[str]) – List or tuple of strings to be added config (MyScaleSettings, Optional) – Myscale configuration text_ids (Optional[Iterable], optional) – IDs for the texts. Defaults to None. batch_size (int, optional) – Batchsize when transmitting data to MyScale. Defaults to 32. metadata (List[dict], optional) – metadata to texts. Defaults to None. into (Other keyword arguments will pass) – [clickhouse-connect](https://clickhouse.com/docs/en/integrations/python#clickhouse-connect-driver-api) Returns MyScale Index property metadata_column: str# similarity_search(query: str, k: int = 4, where_str: Optional[str] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Perform a similarity search with MyScale Parameters query (str) – query string k (int, optional) – Top K neighbors to retrieve. Defaults to 4. where_str (Optional[str], optional) – where condition string. Defaults to None. NOTE – Please do not let end-user to fill this and always be aware of SQL injection. When dealing with metadatas, remember to
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-61
of SQL injection. When dealing with metadatas, remember to use {self.metadata_column}.attribute instead of attribute alone. The default name for it is metadata. Returns List of Documents Return type List[Document] similarity_search_by_vector(embedding: List[float], k: int = 4, where_str: Optional[str] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Perform a similarity search with MyScale by vectors Parameters query (str) – query string k (int, optional) – Top K neighbors to retrieve. Defaults to 4. where_str (Optional[str], optional) – where condition string. Defaults to None. NOTE – Please do not let end-user to fill this and always be aware of SQL injection. When dealing with metadatas, remember to use {self.metadata_column}.attribute instead of attribute alone. The default name for it is metadata. Returns List of (Document, similarity) Return type List[Document] similarity_search_with_relevance_scores(query: str, k: int = 4, where_str: Optional[str] = None, **kwargs: Any) → List[Tuple[langchain.schema.Document, float]][source]# Perform a similarity search with MyScale Parameters query (str) – query string k (int, optional) – Top K neighbors to retrieve. Defaults to 4. where_str (Optional[str], optional) – where condition string. Defaults to None. NOTE – Please do not let end-user to fill this and always be aware of SQL injection. When dealing with metadatas, remember to use {self.metadata_column}.attribute instead of attribute alone. The default name for it is metadata. Returns List of documents most similar to the query text and cosine distance in float for each.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-62
List of documents most similar to the query text and cosine distance in float for each. Lower score represents more similarity. Return type List[Document] pydantic settings langchain.vectorstores.MyScaleSettings[source]# MyScale Client Configuration Attribute: myscale_host (str)An URL to connect to MyScale backend.Defaults to ‘localhost’. myscale_port (int) : URL port to connect with HTTP. Defaults to 8443. username (str) : Username to login. Defaults to None. password (str) : Password to login. Defaults to None. index_type (str): index type string. index_param (dict): index build parameter. database (str) : Database name to find the table. Defaults to ‘default’. table (str) : Table name to operate on. Defaults to ‘vector_table’. metric (str)Metric to compute distance,supported are (‘l2’, ‘cosine’, ‘ip’). Defaults to ‘cosine’. column_map (Dict)Column type map to project column name onto langchainsemantics. Must have keys: text, id, vector, must be same size to number of columns. For example: .. code-block:: python {‘id’: ‘text_id’, ‘vector’: ‘text_embedding’, ‘text’: ‘text_plain’, ‘metadata’: ‘metadata_dictionary_in_json’, } Defaults to identity map. Show JSON schema{ "title": "MyScaleSettings",
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-63
Show JSON schema{ "title": "MyScaleSettings", "description": "MyScale Client Configuration\n\nAttribute:\n myscale_host (str) : An URL to connect to MyScale backend.\n Defaults to 'localhost'.\n myscale_port (int) : URL port to connect with HTTP. Defaults to 8443.\n username (str) : Username to login. Defaults to None.\n password (str) : Password to login. Defaults to None.\n index_type (str): index type string.\n index_param (dict): index build parameter.\n database (str) : Database name to find the table. Defaults to 'default'.\n table (str) : Table name to operate on.\n Defaults to 'vector_table'.\n metric (str) : Metric to compute distance,\n supported are ('l2', 'cosine', 'ip'). Defaults to 'cosine'.\n column_map (Dict) : Column type map to project column name onto langchain\n semantics. Must have keys: `text`, `id`, `vector`,\n must be same size to number of columns. For example:\n .. code-block:: python\n\n {\n 'id': 'text_id',\n 'vector': 'text_embedding',\n 'text': 'text_plain',\n 'metadata': 'metadata_dictionary_in_json',\n }\n\n Defaults to identity map.", "type": "object", "properties": { "host": { "title": "Host", "default": "localhost", "env_names": "{'myscale_host'}", "type": "string" }, "port": { "title": "Port",
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-64
}, "port": { "title": "Port", "default": 8443, "env_names": "{'myscale_port'}", "type": "integer" }, "username": { "title": "Username", "env_names": "{'myscale_username'}", "type": "string" }, "password": { "title": "Password", "env_names": "{'myscale_password'}", "type": "string" }, "index_type": { "title": "Index Type", "default": "IVFFLAT", "env_names": "{'myscale_index_type'}", "type": "string" }, "index_param": { "title": "Index Param", "env_names": "{'myscale_index_param'}", "type": "object", "additionalProperties": { "type": "string" } }, "column_map": { "title": "Column Map", "default": { "id": "id", "text": "text", "vector": "vector", "metadata": "metadata" }, "env_names": "{'myscale_column_map'}", "type": "object", "additionalProperties": { "type": "string" } }, "database": { "title": "Database", "default": "default", "env_names": "{'myscale_database'}", "type": "string" }, "table": { "title": "Table",
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-65
}, "table": { "title": "Table", "default": "langchain", "env_names": "{'myscale_table'}", "type": "string" }, "metric": { "title": "Metric", "default": "cosine", "env_names": "{'myscale_metric'}", "type": "string" } }, "additionalProperties": false } Config env_file: str = .env env_file_encoding: str = utf-8 env_prefix: str = myscale_ Fields column_map (Dict[str, str]) database (str) host (str) index_param (Optional[Dict[str, str]]) index_type (str) metric (str) password (Optional[str]) port (int) table (str) username (Optional[str]) field column_map: Dict[str, str] = {'id': 'id', 'metadata': 'metadata', 'text': 'text', 'vector': 'vector'}# field database: str = 'default'# field host: str = 'localhost'# field index_param: Optional[Dict[str, str]] = None# field index_type: str = 'IVFFLAT'# field metric: str = 'cosine'# field password: Optional[str] = None# field port: int = 8443# field table: str = 'langchain'# field username: Optional[str] = None# class langchain.vectorstores.OpenSearchVectorSearch(opensearch_url: str, index_name: str, embedding_function: langchain.embeddings.base.Embeddings, **kwargs: Any)[source]# Wrapper around OpenSearch as a vector database. Example from langchain import OpenSearchVectorSearch
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-66
Example from langchain import OpenSearchVectorSearch opensearch_vector_search = OpenSearchVectorSearch( "http://localhost:9200", "embeddings", embedding_function ) add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, bulk_size: int = 500, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. bulk_size – Bulk API request count; Default: 500 Returns List of ids from adding the texts into the vectorstore. Optional Args:vector_field: Document field embeddings are stored in. Defaults to “vector_field”. text_field: Document field the text of the document is stored in. Defaults to “text”. classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, bulk_size: int = 500, **kwargs: Any) → langchain.vectorstores.opensearch_vector_search.OpenSearchVectorSearch[source]# Construct OpenSearchVectorSearch wrapper from raw documents. Example from langchain import OpenSearchVectorSearch from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() opensearch_vector_search = OpenSearchVectorSearch.from_texts( texts, embeddings, opensearch_url="http://localhost:9200" ) OpenSearch by default supports Approximate Search powered by nmslib, faiss and lucene engines recommended for large datasets. Also supports brute force search through Script Scoring and Painless Scripting.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-67
search through Script Scoring and Painless Scripting. Optional Args:vector_field: Document field embeddings are stored in. Defaults to “vector_field”. text_field: Document field the text of the document is stored in. Defaults to “text”. Optional Keyword Args for Approximate Search:engine: “nmslib”, “faiss”, “lucene”; default: “nmslib” space_type: “l2”, “l1”, “cosinesimil”, “linf”, “innerproduct”; default: “l2” ef_search: Size of the dynamic list used during k-NN searches. Higher values lead to more accurate but slower searches; default: 512 ef_construction: Size of the dynamic list used during k-NN graph creation. Higher values lead to more accurate graph but slower indexing speed; default: 512 m: Number of bidirectional links created for each new element. Large impact on memory consumption. Between 2 and 100; default: 16 Keyword Args for Script Scoring or Painless Scripting:is_appx_search: False similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs most similar to query. By default supports Approximate Search. Also supports Script Scoring and Painless Scripting. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. Returns List of Documents most similar to the query. Optional Args:vector_field: Document field embeddings are stored in. Defaults to “vector_field”. text_field: Document field the text of the document is stored in. Defaults to “text”. metadata_field: Document field that metadata is stored in. Defaults to “metadata”.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-68
metadata_field: Document field that metadata is stored in. Defaults to “metadata”. Can be set to a special value “*” to include the entire document. Optional Args for Approximate Search:search_type: “approximate_search”; default: “approximate_search” boolean_filter: A Boolean filter consists of a Boolean query that contains a k-NN query and a filter. subquery_clause: Query clause on the knn vector field; default: “must” lucene_filter: the Lucene algorithm decides whether to perform an exact k-NN search with pre-filtering or an approximate search with modified post-filtering. Optional Args for Script Scoring Search:search_type: “script_scoring”; default: “approximate_search” space_type: “l2”, “l1”, “linf”, “cosinesimil”, “innerproduct”, “hammingbit”; default: “l2” pre_filter: script_score query to pre-filter documents before identifying nearest neighbors; default: {“match_all”: {}} Optional Args for Painless Scripting Search:search_type: “painless_scripting”; default: “approximate_search” space_type: “l2Squared”, “l1Norm”, “cosineSimilarity”; default: “l2Squared” pre_filter: script_score query to pre-filter documents before identifying nearest neighbors; default: {“match_all”: {}} similarity_search_with_score(query: str, k: int = 4, **kwargs: Any) → List[Tuple[langchain.schema.Document, float]][source]# Return docs and it’s scores most similar to query. By default supports Approximate Search. Also supports Script Scoring and Painless Scripting. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-69
k – Number of Documents to return. Defaults to 4. Returns List of Documents along with its scores most similar to the query. Optional Args:same as similarity_search class langchain.vectorstores.Pinecone(index: Any, embedding_function: Callable, text_key: str, namespace: Optional[str] = None)[source]# Wrapper around Pinecone vector database. To use, you should have the pinecone-client python package installed. Example from langchain.vectorstores import Pinecone from langchain.embeddings.openai import OpenAIEmbeddings import pinecone # The environment should be the one specified next to the API key # in your Pinecone console pinecone.init(api_key="***", environment="...") index = pinecone.Index("langchain-demo") embeddings = OpenAIEmbeddings() vectorstore = Pinecone(index, embeddings.embed_query, "text") add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, namespace: Optional[str] = None, batch_size: int = 32, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. ids – Optional list of ids to associate with the texts. namespace – Optional pinecone namespace to add the texts to. Returns List of ids from adding the texts into the vectorstore. classmethod from_existing_index(index_name: str, embedding: langchain.embeddings.base.Embeddings, text_key: str = 'text', namespace: Optional[str] = None) → langchain.vectorstores.pinecone.Pinecone[source]# Load pinecone vectorstore from index name.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-70
Load pinecone vectorstore from index name. classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, batch_size: int = 32, text_key: str = 'text', index_name: Optional[str] = None, namespace: Optional[str] = None, **kwargs: Any) → langchain.vectorstores.pinecone.Pinecone[source]# Construct Pinecone wrapper from raw documents. This is a user friendly interface that: Embeds documents. Adds the documents to a provided Pinecone index This is intended to be a quick way to get started. Example from langchain import Pinecone from langchain.embeddings import OpenAIEmbeddings import pinecone # The environment should be the one specified next to the API key # in your Pinecone console pinecone.init(api_key="***", environment="...") embeddings = OpenAIEmbeddings() pinecone = Pinecone.from_texts( texts, embeddings, index_name="langchain-demo" ) max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[dict] = None, namespace: Optional[str] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-71
lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[dict] = None, namespace: Optional[str] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters embedding – Embedding to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. similarity_search(query: str, k: int = 4, filter: Optional[dict] = None, namespace: Optional[str] = None, **kwargs: Any) → List[langchain.schema.Document][source]# Return pinecone documents most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter – Dictionary of argument(s) to filter on metadata namespace – Namespace to search in. Default will search in ‘’ namespace. Returns List of Documents most similar to the query and score for each
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-72
Returns List of Documents most similar to the query and score for each similarity_search_with_score(query: str, k: int = 4, filter: Optional[dict] = None, namespace: Optional[str] = None) → List[Tuple[langchain.schema.Document, float]][source]# Return pinecone documents most similar to query, along with scores. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter – Dictionary of argument(s) to filter on metadata namespace – Namespace to search in. Default will search in ‘’ namespace. Returns List of Documents most similar to the query and score for each class langchain.vectorstores.Qdrant(client: Any, collection_name: str, embeddings: Optional[langchain.embeddings.base.Embeddings] = None, content_payload_key: str = 'page_content', metadata_payload_key: str = 'metadata', embedding_function: Optional[Callable] = None)[source]# Wrapper around Qdrant vector database. To use you should have the qdrant-client package installed. Example from qdrant_client import QdrantClient from langchain import Qdrant client = QdrantClient() collection_name = "MyCollection" qdrant = Qdrant(client, collection_name, embedding_function) CONTENT_KEY = 'page_content'# METADATA_KEY = 'metadata'# add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[Sequence[str]] = None, batch_size: int = 64, **kwargs: Any) → List[str][source]# Run more texts through the embeddings and add to the vectorstore. Parameters texts – Iterable of strings to add to the vectorstore.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-73
Parameters texts – Iterable of strings to add to the vectorstore. metadatas – Optional list of metadatas associated with the texts. ids – Optional list of ids to associate with the texts. Ids have to be uuid-like strings. batch_size – How many vectors upload per-request. Default: 64 Returns List of ids from adding the texts into the vectorstore. classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, ids: Optional[Sequence[str]] = None, location: Optional[str] = None, url: Optional[str] = None, port: Optional[int] = 6333, grpc_port: int = 6334, prefer_grpc: bool = False, https: Optional[bool] = None, api_key: Optional[str] = None, prefix: Optional[str] = None, timeout: Optional[float] = None, host: Optional[str] = None, path: Optional[str] = None, collection_name: Optional[str] = None, distance_func: str = 'Cosine', content_payload_key: str = 'page_content', metadata_payload_key: str = 'metadata', batch_size: int = 64, shard_number: Optional[int] = None, replication_factor: Optional[int] = None, write_consistency_factor: Optional[int] = None, on_disk_payload: Optional[bool] = None, hnsw_config: Optional[common_types.HnswConfigDiff] = None, optimizers_config: Optional[common_types.OptimizersConfigDiff] = None, wal_config: Optional[common_types.WalConfigDiff] = None, quantization_config: Optional[common_types.QuantizationConfig] = None, init_from: Optional[common_types.InitFrom] = None, **kwargs: Any) → Qdrant[source]#
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-74
Construct Qdrant wrapper from a list of texts. Parameters texts – A list of texts to be indexed in Qdrant. embedding – A subclass of Embeddings, responsible for text vectorization. metadatas – An optional list of metadata. If provided it has to be of the same length as a list of texts. ids – Optional list of ids to associate with the texts. Ids have to be uuid-like strings. location – If :memory: - use in-memory Qdrant instance. If str - use it as a url parameter. If None - fallback to relying on host and port parameters. url – either host or str of “Optional[scheme], host, Optional[port], Optional[prefix]”. Default: None port – Port of the REST API interface. Default: 6333 grpc_port – Port of the gRPC interface. Default: 6334 prefer_grpc – If true - use gPRC interface whenever possible in custom methods. Default: False https – If true - use HTTPS(SSL) protocol. Default: None api_key – API key for authentication in Qdrant Cloud. Default: None prefix – If not None - add prefix to the REST URL path. Example: service/v1 will result in http://localhost:6333/service/v1/{qdrant-endpoint} for REST API. Default: None timeout – Timeout for REST and gRPC API requests. Default: 5.0 seconds for REST and unlimited for gRPC host – Host name of Qdrant service. If url and host are None, set to ‘localhost’. Default: None path – Path in which the vectors will be stored while using local mode. Default: None collection_name – Name of the Qdrant collection to be used. If not provided,
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-75
collection_name – Name of the Qdrant collection to be used. If not provided, it will be created randomly. Default: None distance_func – Distance function. One of: “Cosine” / “Euclid” / “Dot”. Default: “Cosine” content_payload_key – A payload key used to store the content of the document. Default: “page_content” metadata_payload_key – A payload key used to store the metadata of the document. Default: “metadata” batch_size – How many vectors upload per-request. Default: 64 shard_number – Number of shards in collection. Default is 1, minimum is 1. replication_factor – Replication factor for collection. Default is 1, minimum is 1. Defines how many copies of each shard will be created. Have effect only in distributed mode. write_consistency_factor – Write consistency factor for collection. Default is 1, minimum is 1. Defines how many replicas should apply the operation for us to consider it successful. Increasing this number will make the collection more resilient to inconsistencies, but will also make it fail if not enough replicas are available. Does not have any performance impact. Have effect only in distributed mode. on_disk_payload – If true - point`s payload will not be stored in memory. It will be read from the disk every time it is requested. This setting saves RAM by (slightly) increasing the response time. Note: those payload values that are involved in filtering and are indexed - remain in RAM. hnsw_config – Params for HNSW index optimizers_config – Params for optimizer wal_config – Params for Write-Ahead-Log quantization_config – Params for quantization, if None - quantization will be disabled init_from – Use data stored in another collection to initialize this collection
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-76
init_from – Use data stored in another collection to initialize this collection **kwargs – Additional arguments passed directly into REST client initialization This is a user-friendly interface that: 1. Creates embeddings, one for each text 2. Initializes the Qdrant database as an in-memory docstore by default (and overridable to a remote docstore) Adds the text embeddings to the Qdrant database This is intended to be a quick way to get started. Example from langchain import Qdrant from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() qdrant = Qdrant.from_texts(texts, embeddings, "localhost") max_marginal_relevance_search(query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any) → List[langchain.schema.Document][source]# Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. fetch_k – Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. lambda_mult – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-77
Defaults to 0.5. Returns List of Documents selected by maximal marginal relevance. similarity_search(query: str, k: int = 4, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, offset: int = 0, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) → List[Document][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter – Filter by metadata. Defaults to None. search_params – Additional search params offset – Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues. score_threshold – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. consistency – Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas ’majority’ - query all replicas, but return values present in themajority of replicas ’quorum’ - query the majority of replicas, return values present inall of them ’all’ - query all replicas, and return values present in all replicas Returns List of Documents most similar to the query.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-78
Returns List of Documents most similar to the query. similarity_search_with_score(query: str, k: int = 4, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, offset: int = 0, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) → List[Tuple[Document, float]][source]# Return docs most similar to query. Parameters query – Text to look up documents similar to. k – Number of Documents to return. Defaults to 4. filter – Filter by metadata. Defaults to None. search_params – Additional search params offset – Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues. score_threshold – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. consistency – Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas ’majority’ - query all replicas, but return values present in themajority of replicas ’quorum’ - query the majority of replicas, return values present inall of them ’all’ - query all replicas, and return values present in all replicas Returns List of documents most similar to the query text and cosine distance in float for each. Lower score represents more similarity.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html
6d5c37c1dbcb-79
distance in float for each. Lower score represents more similarity. class langchain.vectorstores.Redis(redis_url: str, index_name: str, embedding_function: typing.Callable, content_key: str = 'content', metadata_key: str = 'metadata', vector_key: str = 'content_vector', relevance_score_fn: typing.Optional[typing.Callable[[float], float]] = <function _default_relevance_score>, **kwargs: typing.Any)[source]# Wrapper around Redis vector database. To use, you should have the redis python package installed. Example from langchain.vectorstores import Redis from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() vectorstore = Redis( redis_url="redis://username:password@localhost:6379" index_name="my-index", embedding_function=embeddings.embed_query, ) add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, embeddings: Optional[List[List[float]]] = None, keys: Optional[List[str]] = None, batch_size: int = 1000, **kwargs: Any) → List[str][source]# Add more texts to the vectorstore. Parameters texts (Iterable[str]) – Iterable of strings/text to add to the vectorstore. metadatas (Optional[List[dict]], optional) – Optional list of metadatas. Defaults to None. embeddings (Optional[List[List[float]]], optional) – Optional pre-generated embeddings. Defaults to None. keys (Optional[List[str]], optional) – Optional key values to use as ids. Defaults to None. batch_size (int, optional) – Batch size to use for writes. Defaults to 1000. Returns List of ids added to the vectorstore Return type List[str]
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/vectorstores.html