123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- ---
- title: '📋 Supported data formats'
- ---
- ## Automatic data type detection
- The add method automatically tries to detect the data_type, based on your input for the source argument. So `app.add('https://www.youtube.com/watch?v=dQw4w9WgXcQ')` is enough to embed a YouTube video.
- This detection is implemented for all formats. It is based on factors such as whether it's a URL, a local file, the source data type, etc.
- ### Debugging automatic detection
- Set `log_level=DEBUG` (in [AppConfig](http://localhost:3000/advanced/query_configuration#appconfig)) and make sure it's working as intended.
- Otherwise, you will not know when, for instance, an invalid filepath is interpreted as raw text instead.
- ### Forcing a data type
- To omit any issues with the data type detection, you can **force** a data_type by adding it as a `add` method argument.
- The examples below show you the keyword to force the respective `data_type`.
- Forcing can also be used for edge cases, such as interpreting a sitemap as a web_page, for reading it's raw text instead of following links.
- ## Remote Data Types
- <Tip>
- **Use local files in remote data types**
- Some data_types are meant for remote content and only work with URLs.
- You can pass local files by formatting the path using the `file:` [URI scheme](https://en.wikipedia.org/wiki/File_URI_scheme), e.g. `file:///info.pdf`.
- </Tip>
- ### Youtube video
- To add any youtube video to your app, use the data_type (first argument to `.add()` method) as `youtube_video`. Eg:
- ```python
- app.add('a_valid_youtube_url_here', data_type='youtube_video')
- ```
- ### PDF file
- To add any pdf file, use the data_type as `pdf_file`. Eg:
- ```python
- app.add('a_valid_url_where_pdf_file_can_be_accessed', data_type='pdf_file')
- ```
- Note that we do not support password protected pdfs.
- ### Web page
- To add any web page, use the data_type as `web_page`. Eg:
- ```python
- app.add('a_valid_web_page_url', data_type='web_page')
- ```
- ### Sitemap
- Add all web pages from an xml-sitemap. Filters non-text files. Use the data_type as `sitemap`. Eg:
- ```python
- app.add('https://example.com/sitemap.xml', data_type='sitemap')
- ```
- ### Doc file
- To add any doc/docx file, use the data_type as `docx`. `docx` allows remote urls and conventional file paths. Eg:
- ```python
- app.add('https://example.com/content/intro.docx', data_type="docx")
- app.add('content/intro.docx', data_type="docx")
- ```
- ### Code documentation website loader
- To add any code documentation website as a loader, use the data_type as `docs_site`. Eg:
- ```python
- app.add("https://docs.embedchain.ai/", data_type="docs_site")
- ```
- ### Notion
- To use notion you must install the extra dependencies with `pip install embedchain[notion]`.
- To load a notion page, use the data_type as `notion`. Since it is hard to automatically detect, forcing this is advised.
- The next argument must **end** with the `notion page id`. The id is a 32-character string. Eg:
- ```python
- app.add("cfbc134ca6464fc980d0391613959196", "notion")
- app.add("my-page-cfbc134ca6464fc980d0391613959196", "notion")
- app.add("https://www.notion.so/my-page-cfbc134ca6464fc980d0391613959196", "notion")
- ```
- ## Local Data Types
- ### Text
- To supply your own text, use the data_type as `text` and enter a string. The text is not processed, this can be very versatile. Eg:
- ```python
- app.add('Seek wealth, not money or status. Wealth is having assets that earn while you sleep. Money is how we transfer time and wealth. Status is your place in the social hierarchy.', data_type='text')
- ```
- Note: This is not used in the examples because in most cases you will supply a whole paragraph or file, which did not fit.
- ### QnA pair
- To supply your own QnA pair, use the data_type as `qna_pair` and enter a tuple. Eg:
- ```python
- app.add(("Question", "Answer"), data_type="qna_pair")
- ```
- ## Reusing a vector database
- Default behavior is to create a persistent vector DB in the directory **./db**. You can split your application into two Python scripts: one to create a local vector DB and the other to reuse this local persistent vector DB. This is useful when you want to index hundreds of documents and separately implement a chat interface.
- Create a local index:
- ```python
- from embedchain import App
- naval_chat_bot = App()
- naval_chat_bot.add("https://www.youtube.com/watch?v=3qHkcs3kG44")
- naval_chat_bot.add("https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf")
- ```
- You can reuse the local index with the same code, but without adding new documents:
- ```python
- from embedchain import App
- naval_chat_bot = App()
- print(naval_chat_bot.query("What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?"))
- ```
- ## More formats (coming soon!)
- - If you want to add any other format, please create an [issue](https://github.com/embedchain/embedchain/issues) and we will add it to the list of supported formats.
|