From 50f88586f0c57572843940098147efe5ba0891fa Mon Sep 17 00:00:00 2001 From: Matthew Zhou Date: Wed, 20 Nov 2024 17:18:39 -0800 Subject: [PATCH] fix: Lazy load `llamaindex` imports that are causing issues (#2075) --- letta/embeddings.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/letta/embeddings.py b/letta/embeddings.py index ead188f7..632719d8 100644 --- a/letta/embeddings.py +++ b/letta/embeddings.py @@ -3,18 +3,7 @@ import uuid from typing import Any, List, Optional import numpy as np - -# from llama_index.core.base.embeddings import BaseEmbedding -# from llama_index.core.embeddings import BaseEmbedding -# from llama_index.core.base.embeddings.base import BaseEmbedding -# from llama_index.bridge.pydantic import PrivateAttr -# from llama_index.embeddings.base import BaseEmbedding -# from llama_index.embeddings.huggingface_utils import format_text import tiktoken -from llama_index.core import Document as LlamaIndexDocument - -# from llama_index.core.base.embeddings import BaseEmbedding -from llama_index.core.node_parser import SentenceSplitter from letta.constants import ( EMBEDDING_TO_TOKENIZER_DEFAULT, @@ -26,6 +15,9 @@ from letta.utils import is_valid_url, printd def parse_and_chunk_text(text: str, chunk_size: int) -> List[str]: + from llama_index.core import Document as LlamaIndexDocument + from llama_index.core.node_parser import SentenceSplitter + parser = SentenceSplitter(chunk_size=chunk_size) llama_index_docs = [LlamaIndexDocument(text=text)] nodes = parser.get_nodes_from_documents(llama_index_docs)