Skip to content

Fix IndexStats returning attribute names instead of values #1095

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions meilisearch/models/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from enum import Enum
from typing import Any, Dict, Iterator, List, Optional
from typing import Any, Dict, Iterator, List, Optional, Union

from camel_converter import to_snake
from camel_converter.pydantic_base import CamelBase
Expand All @@ -21,7 +21,7 @@ def __init__(self, doc: Dict[str, Any]) -> None:

def __getattr__(self, attr: str) -> Any:
if attr in self.__dict.keys():
return attr
return self.__dict[attr]
raise AttributeError(f"{self.__class__.__name__} object has no attribute {attr}")

def __iter__(self) -> Iterator:
Expand Down Expand Up @@ -62,3 +62,65 @@ class EmbedderDistribution(CamelBase):
class LocalizedAttributes(CamelBase):
attribute_patterns: List[str]
locales: List[str]


class OpenAiEmbedder(CamelBase):
source: str = "openAi"
url: Optional[str] = None
model: Optional[str] = None # Defaults to text-embedding-3-small
dimensions: Optional[int] = None # Uses the model default
api_key: Optional[str] = None # Can be provided through a CLI option or environment variable
document_template: Optional[str] = None
document_template_max_bytes: Optional[int] = None # Default to 400
distribution: Optional[EmbedderDistribution] = None
binary_quantized: Optional[bool] = None


class HuggingFaceEmbedder(CamelBase):
source: str = "huggingFace"
model: Optional[str] = None # Defaults to BAAI/bge-base-en-v1.5
revision: Optional[str] = None
document_template: Optional[str] = None
document_template_max_bytes: Optional[int] = None # Default to 400
distribution: Optional[EmbedderDistribution] = None
binary_quantized: Optional[bool] = None


class OllamaEmbedder(CamelBase):
source: str = "ollama"
url: Optional[str] = None
api_key: Optional[str] = None
model: str
document_template: Optional[str] = None
document_template_max_bytes: Optional[int] = None # Default to 400
distribution: Optional[EmbedderDistribution] = None
binary_quantized: Optional[bool] = None


class RestEmbedder(CamelBase):
source: str = "rest"
url: str
api_key: Optional[str] # required for protected APIs
document_template: Optional[str] = None
document_template_max_bytes: Optional[int] = None # Default to 400
request: Dict[str, Any]
response: Dict[str, Any]
distribution: Optional[EmbedderDistribution] = None
headers: Optional[Dict[str, Any]] = None
binary_quantized: Optional[bool] = None


class UserProvidedEmbedder(CamelBase):
source: str = "userProvided"
dimensions: int
distribution: Optional[EmbedderDistribution] = None
binary_quantized: Optional[bool] = None


class Embedders(CamelBase):
embedders: Dict[
str,
Union[
OpenAiEmbedder, HuggingFaceEmbedder, OllamaEmbedder, RestEmbedder, UserProvidedEmbedder
],
]
2 changes: 1 addition & 1 deletion tests/models/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def test_getattr():
document = IndexStats({"field1": "test 1", "fiels2": "test 2"})
assert document.__getattr__("field1") == "field1"
assert document.__getattr__("field1") == "test 1"


def test_getattr_not_found():
Expand Down