Connection

Create a connection to a live service.

class pinecone.connector.Connection(host: str, port: int, api_key: str = None, service_name: str = None, timeout: int = 0)

A connection manages communication with a service.

You can only interact with a service (e.g. upsert, query) after a connection to the service has been established.

Namespaces partition the items in an index. When you read from or write to a namespace in an index, you will only access items in that particular namespace. For instance, two namespaces can contain the items with the same ids but different values. Use namespaces when you want to use the same preprocessors and postprocessors for separate datasets. For example, if you are building a movie recommender system, then you could use namespaces to separate the recommendations by genre.

Parameters
  • host (str) – service host

  • port (int) – service port

  • api_key (str, optional) – user API key, defaults to None

  • service_name (str, optional) – name of the service, defaults to None

  • timeout (int, optional) – defaults to 0. Timeout to retry connection if gRPC is unavailable. 0 is no retry.

close()

Closes the connection.

delete(ids: Iterable[str], namespace: str = None, batch_size: int = None)pinecone.connector.Cursor

Deletes items by their ids.

Parameters
  • ids (Iterable[str]) – ids of items

  • namespace (str, optional) – a partition in an index. Use default namespace when not specified.

  • batch_size (int, optional) – overrides default batch size

Returns

Cursor

fetch(ids: Iterable[str], namespace: str = None, batch_size: int = None)pinecone.connector.Cursor

Fetches items by their ids.

Parameters
  • ids (Iterable[str]) – ids of items

  • namespace (str, optional) – a partition in an index. Use default namespace when not specified.

  • batch_size (int, optional) – overrides default batch size

Returns

Cursor

info(namespace: str = None)pinecone.connector.InfoResult

Returns information of the index.

query(queries: Iterable[numpy.ndarray], namespace: str = None, top_k: int = 10, batch_size: int = None, include_data: bool = False)pinecone.connector.Cursor

Sends queries to the index and returns the top results ordered by their scores.

Parameters
  • queries (Iterable[np.ndarray]) – queries

  • namespace (str, optional) – a partition in an index. Use default namespace when not specified.

  • top_k (int, optional) – defaults to 10, the number of top query results to return for each query, ordered by their scores

  • batch_size (int, optional) – overrides default batch size

  • include_data (bool, optional) – whether to return data associated with the query results, defaults to False

Returns

Cursor

upsert(items: Iterable[Tuple[str, numpy.ndarray]], namespace: str = None, batch_size: int = None)pinecone.connector.Cursor

Inserts or updates items.

Insert an item into the index, or update by item id if the item’s id already exists.

Parameters
  • items (Iterable[Tuple[str, np.ndarray]]) – tuples of the form (id, numpy.ndarray)

  • namespace (str, optional) – a partition in an index. Use default namespace when not specified.

  • batch_size (int, optional) – overrides default batch size

Returns

Cursor

class pinecone.connector.Cursor(config: pinecone.connector.CursorConfig, items: Iterable[numpy.ndarray], batch_size: int = 100)

A cursor batch-processes requests sent to a service.

Parameters
  • config (CursorConfig) – cursor configurations

  • items (Iterable[np.ndarray]) – Items to process

  • batch_size (int, optional) – the number of items to batch-process, defaults to 100

collect()

Processes all of the items and returns the results.

classmethod identity(entity)

An identity function.

stream()

Processes all of the items, returns the results one batch at a time.

take(size: int)

Processes a given number of items and returns the results.

Parameters

size – the number of items to process

class pinecone.connector.DeleteResult(id: str)

Result of a delete request.

Create new instance of DeleteResult(id,)

property id

Alias for field number 0

class pinecone.connector.FetchResult(id: str, vector: numpy.ndarray)

Result of a fetch request

Create new instance of FetchResult(id, vector)

property id

Alias for field number 0

property vector

Alias for field number 1

class pinecone.connector.IndexResult(id: str)

Result of an index request.

Create new instance of IndexResult(id,)

property id

Alias for field number 0

class pinecone.connector.InfoResult(index_size: str)

Result of an info request

Create new instance of InfoResult(index_size,)

property index_size

Alias for field number 0

class pinecone.connector.QueryResult(ids: Iterable[str], scores: Iterable[float], data: numpy.ndarray = None)

Result of a query request.

Create new instance of QueryResult(ids, scores, data)

property data

Alias for field number 2

property ids

Alias for field number 0

property scores

Alias for field number 1

pinecone.connector.connect(service_name: str = None, router_name: str = None, timeout: int = 0)pinecone.connector.Connection

Connects to a live service/router and returns an instance of Connection.

Parameters
  • service_name (str) – name of a service.

  • router_name (str) – name of a router.

  • timeout (int, optional) – gRPC connection timeout, defaults to 0

Returns

Connection