-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add database data source (MySQL and PostgreSQL) (#28)
- Loading branch information
Showing
6 changed files
with
187 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-llama": patch | ||
--- | ||
|
||
Use databases as data source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
import logging | ||
from typing import List | ||
from pydantic import BaseModel, validator | ||
from llama_index.core.indices.vector_store import VectorStoreIndex | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class DBLoaderConfig(BaseModel): | ||
uri: str | ||
queries: List[str] | ||
|
||
|
||
def get_db_documents(configs: list[DBLoaderConfig]): | ||
from llama_index.readers.database import DatabaseReader | ||
|
||
docs = [] | ||
for entry in configs: | ||
loader = DatabaseReader(uri=entry.uri) | ||
for query in entry.queries: | ||
logger.info(f"Loading data from database with query: {query}") | ||
documents = loader.load_data(query=query) | ||
docs.extend(documents) | ||
|
||
return documents |