Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: Implement lazy_load() for CubeSemanticLoader #18535

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
import time
from typing import List
from typing import Iterator, List

import requests
from langchain_core.documents import Document
Expand Down Expand Up @@ -99,7 +99,7 @@ def _get_dimension_values(self, dimension_name: str) -> List[str]:
logger.info("Maximum retries reached.")
return []

def load(self) -> List[Document]:
def lazy_load(self) -> Iterator[Document]:
"""Makes a call to Cube's REST API metadata endpoint.

Returns:
Expand Down Expand Up @@ -131,8 +131,6 @@ def load(self) -> List[Document]:
if not cube_data_objects:
raise ValueError("No cubes found in metadata.")

docs = []

for cube_data_obj in cube_data_objects:
cube_data_obj_name = cube_data_obj.get("name")
cube_data_obj_type = cube_data_obj.get("type")
Expand Down Expand Up @@ -173,6 +171,4 @@ def load(self) -> List[Document]:
page_content = f"{str(item.get('title'))}, "
page_content += f"{str(item.get('description'))}"

docs.append(Document(page_content=page_content, metadata=metadata))

return docs
yield Document(page_content=page_content, metadata=metadata)