| 11 | |
| 12 | |
| 13 | class Item(Base): |
| 14 | __tablename__ = "items" |
| 15 | id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) |
| 16 | type: Mapped[str] = mapped_column() |
| 17 | brand: Mapped[str] = mapped_column() |
| 18 | name: Mapped[str] = mapped_column() |
| 19 | description: Mapped[str] = mapped_column() |
| 20 | price: Mapped[float] = mapped_column() |
| 21 | # Embeddings for different models: |
| 22 | embedding_3l: Mapped[Vector] = mapped_column(Vector(1024), nullable=True) # text-embedding-3-large |
| 23 | embedding_nomic: Mapped[Vector] = mapped_column(Vector(768), nullable=True) # nomic-embed-text |
| 24 | |
| 25 | def to_dict(self, include_embedding: bool = False): |
| 26 | model_dict = {column.name: getattr(self, column.name) for column in self.__table__.columns} |
| 27 | if include_embedding: |
| 28 | model_dict["embedding_3l"] = model_dict.get("embedding_3l", []) |
| 29 | model_dict["embedding_nomic"] = model_dict.get("embedding_nomic", []) |
| 30 | else: |
| 31 | del model_dict["embedding_3l"] |
| 32 | del model_dict["embedding_nomic"] |
| 33 | return model_dict |
| 34 | |
| 35 | def to_str_for_rag(self): |
| 36 | return f"Name:{self.name} Description:{self.description} Price:{self.price} Brand:{self.brand} Type:{self.type}" |
| 37 | |
| 38 | def to_str_for_embedding(self): |
| 39 | return f"Name: {self.name} Description: {self.description} Type: {self.type}" |
| 40 | |
| 41 | |
| 42 | """ |