0
0
LangChainframework~10 mins

Loading from databases in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the correct database loader from LangChain.

LangChain
from langchain.document_loaders import [1]
Drag options to blanks, or click blank then click option'
ASQLDatabaseLoader
BCSVLoader
CTextLoader
DPDFLoader
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a loader meant for files like CSV or PDF instead of databases.
2fill in blank
medium

Complete the code to create a connection string for a SQLite database.

LangChain
connection_string = 'sqlite:///[1]'
Drag options to blanks, or click blank then click option'
Amydatabase
Bmydatabase.db
Cdatabase.sqlite3
Ddb.sqlite
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the file extension in the connection string.
Using just the database name without extension.
3fill in blank
hard

Fix the error in the code to load documents from a SQL database using LangChain.

LangChain
from langchain.document_loaders import SQLDatabaseLoader
loader = SQLDatabaseLoader(connection_string=[1])
docs = loader.load()
Drag options to blanks, or click blank then click option'
A'sqlite:///mydatabase.db'
Bmydatabase.db
Csqlite:///mydatabase.db
D'mydatabase.db'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the connection string without quotes causing a syntax error.
Using incomplete connection strings.
4fill in blank
hard

Fill both blanks to create a SQLDatabaseLoader and load documents.

LangChain
from langchain.document_loaders import [1]
loader = [2](connection_string='sqlite:///example.db')
docs = loader.load()
Drag options to blanks, or click blank then click option'
ASQLDatabaseLoader
BCSVLoader
DTextLoader
Attempts:
3 left
💡 Hint
Common Mistakes
Importing one loader but trying to instantiate another.
Using loaders meant for files instead of databases.
5fill in blank
hard

Fill all three blanks to create a SQLDatabaseLoader, load documents, and print the number of documents loaded.

LangChain
from langchain.document_loaders import [1]
loader = [2](connection_string='sqlite:///data.db')
docs = loader.[3]()
print(len(docs))
Drag options to blanks, or click blank then click option'
ASQLDatabaseLoader
Cload
Dload_documents
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong method name like load_documents() which does not exist.
Mismatching import and instance names.