Skip to content

Commit

Permalink
Adjust fetch return type
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamon committed Dec 13, 2024
1 parent 9ab6faf commit 6ddc079
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions pinecone/data/dataclasses/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .sparse_values import SparseValues
from .vector import Vector
from .fetch_response import FetchResponse
11 changes: 11 additions & 0 deletions pinecone/data/dataclasses/fetch_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from dataclasses import dataclass
from typing import Dict

from .vector import Vector


@dataclass
class FetchResponse:
namespace: str
vectors: Dict[str, Vector]
usage: Dict[str, int]
10 changes: 7 additions & 3 deletions pinecone/data/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pinecone.core.openapi.db_data.api.vector_operations_api import VectorOperationsApi
from pinecone.core.openapi.db_data import API_VERSION
from pinecone.core.openapi.db_data.models import (
FetchResponse,
QueryRequest,
QueryResponse,
RpcStatus,
Expand All @@ -24,7 +23,7 @@
DescribeIndexStatsRequest,
ListResponse,
)
from .dataclasses import Vector, SparseValues
from .dataclasses import Vector, SparseValues, FetchResponse
from .interfaces import IndexInterface
from .request_factory import IndexRequestFactory
from .features.bulk_import import ImportFeatureMixin
Expand Down Expand Up @@ -234,7 +233,12 @@ def delete(
@validate_and_convert_errors
def fetch(self, ids: List[str], namespace: Optional[str] = None, **kwargs) -> FetchResponse:
args_dict = parse_non_empty_args([("namespace", namespace)])
return self._vector_api.fetch_vectors(ids=ids, **args_dict, **kwargs)
result = self._vector_api.fetch_vectors(ids=ids, **args_dict, **kwargs)
return FetchResponse(
namespace=namespace,
vectors={k: Vector.from_dict(v) for k, v in result.vectors},
usage=result.usage,
)

@validate_and_convert_errors
def query(
Expand Down

0 comments on commit 6ddc079

Please sign in to comment.