Skip to content

Commit

Permalink
fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
kdziedzic68 committed Nov 26, 2024
1 parent fb2a901 commit 0e08605
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion examples/apps/documents_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ async def _handle_message(
if not self._documents_ingested:
yield self.NO_DOCUMENTS_INGESTED_MESSAGE
results = await self.document_search.search(message[-1])
prompt = RAGPrompt(QueryWithContext(query=message, context=[i.text_representation for i in results]))
prompt = RAGPrompt(
QueryWithContext(query=message, context=[i.text_representation for i in results if i.text_representation])
)
response = await self._llm.generate(prompt)
yield response.answer

Expand Down
1 change: 1 addition & 0 deletions packages/ragbits-core/src/ragbits/core/embeddings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class EmbeddingTypes(Enum):
"""
Enum for listing supported embedding types
"""

TEXT: str = "text"
IMAGE: str = "image"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ async def insert_elements(self, elements: list[Element]) -> None:
"""
elements_with_text = [element for element in elements if element.key]
images_with_text = [element for element in elements_with_text if isinstance(element, ImageElement)]
vectors = await self.embedder.embed_text([element.key for element in elements_with_text])
vectors = await self.embedder.embed_text([element.key for element in elements_with_text if element.key])

image_elements = [element for element in elements if isinstance(element, ImageElement)]

num_images_with_no_textual_repr = len(image_elements) - len(images_with_text)
if num_images_with_no_textual_repr > 0:
warnings.warn(
f"{len(image_elements) - len(images_with_text)} of {len(image_elements)}"
f"Have no textual representation"
"Have no textual representation and have not been text emedded"
)

entries = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def key(self) -> str | None:
@computed_field # type: ignore[prop-decorator]
@property
@abstractmethod
def text_representation(self) -> str:
def text_representation(self) -> str | None:
"""
Get the text representation of the element.
Expand Down Expand Up @@ -116,7 +116,7 @@ def to_vector_db_entry(self, vector: list[float], embedding_type: EmbeddingTypes
metadata["embedding_type"] = str(embedding_type)
return VectorStoreEntry(
id=vector_store_entry_id,
key=self.key,
key=self.key or "null",
vector=vector,
metadata=metadata,
)
Expand Down

0 comments on commit 0e08605

Please sign in to comment.