noop.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """
  2. The `vecs.experimental.adapter.noop` module provides a default no-op (no operation) adapter
  3. that passes the inputs through without any modification. This can be useful when no specific
  4. adapter processing is required.
  5. All public classes, enums, and functions are re-exported by `vecs.adapters` module.
  6. """
  7. from typing import Generator, Iterable, Optional
  8. from .base import AdapterContext, AdapterStep, Record
  9. class NoOp(AdapterStep):
  10. """
  11. NoOp is a no-operation AdapterStep. It is a default adapter that passes through
  12. the input records without any modifications.
  13. """
  14. def __init__(self, dimension: int):
  15. """
  16. Initializes the NoOp adapter with a dimension.
  17. Args:
  18. dimension (int): The dimension of the input vectors.
  19. """
  20. self._dimension = dimension
  21. @property
  22. def exported_dimension(self) -> Optional[int]:
  23. """
  24. Returns the dimension of the adapter.
  25. Returns:
  26. int: The dimension of the input vectors.
  27. """
  28. return self._dimension
  29. def __call__(
  30. self,
  31. records: Iterable[Record],
  32. adapter_context: AdapterContext,
  33. ) -> Generator[Record, None, None]:
  34. for record in records:
  35. (
  36. id,
  37. document_id,
  38. user_id,
  39. collection_ids,
  40. vec,
  41. text,
  42. metadata,
  43. ) = record
  44. yield (
  45. str(id),
  46. str(document_id),
  47. str(user_id),
  48. [str(gid) for gid in collection_ids],
  49. vec,
  50. text,
  51. metadata or {},
  52. )