Graph

A Pinecone graph is a serialization of a Pinecone service. It describes how the service handles requests and how functions in the service should be deployed.

class pinecone.graph.IndexGraph(engine_type: str = 'approximated', metric: str = 'cosine', shards: int = 1, replicas: int = 1)

Bases: pinecone.graph.Graph

The graphical representation of an index service.

An index service consists of preprocessors, the vector index, and postprocessors. Preprocessors modify the items before indexing them, or modify the queries before retrieving results from the index. Examples of preprocessors include matrix fatorization models for transforming movie ids into embeddings, and BERT transformers for text data. Postprocessors modify the retrieved results of queries. Examples of postprocessors include re-rankers for balancing recommendation fairness, or imputation functions for increasing diversity.

Parameters
  • engine_type (str, optional) – type of engine, one of {“approximated”, “exact”}, defaults to “approximated”. The “approximated” engine uses fast approximate search algorithms developed by Pinecone. The “exact” engine uses accurate exact search algorithms. It performs exhaustive searches and thus it is usually slower than the “approximated” engine.

  • metric (str, optional) – type of metric used in the vector index, one of {“cosine”, “dotproduct”, “euclidean”}, defaults to “cosine”. Use “cosine” for cosine similarity, “dotproduct” for dot-product, and “euclidean” for euclidean distance.

  • shards (int, optional) – the number of shards for the engine, defaults to 1. As a general guideline, use 1 shard per 1 GB of data.

  • replicas (int, optional) – the number of replicas, defaults to 1. Use at least 2 replicas if you need high availability (99.99% uptime) for querying. For every 100 QPS your service needs to support, provision a replica.

add_postprocessor(image_uri: str = None, config: dict = None, fn: pinecone.functions.Function = None)

Adds a postprocessor to the graph.

You can add mutiple postprocessors to a graph. Postprocessors are on the “read” path of a graph and modify results of a query request.

Parameters
  • image_uri (str, optional) – a Pinecone Model Hub docker image URI, defaults to None

  • config (dict, optional) – configurations for HubFunction, defaults to None

  • fn (Function, optional) – an instance of a Pinecone Function, defaults to None. For custom functions, use HubFunction. If specified, image_uri and config will be ignored.

add_preprocessor(path: str, image_uri: str = None, config: dict = None, fn: pinecone.functions.Function = None)

Adds a preprocessor to the given path of the graph.

You can add multiple preprocessors to the same path in a graph. query requests flow through the read path of the graph, and upsert requests flow through the write path of the graph.

Parameters
  • path ({"read", "write"}) – the path in the graph to add the preprocessor to

  • image_uri (str, optional) – a Pinecone Model Hub docker image URI, defaults to None

  • config (dict, optional) – configurations for HubFunction, defaults to None

  • fn (Function, optional) – an instance of a Pinecone Function, defaults to None. For custom functions, use HubFunction. If specified, image_uri and config will be ignored.

add_read_preprocessor(image_uri: str = None, config: dict = None, fn: pinecone.functions.Function = None)

Adds a preprocessor to the “read” path of the graph.

See add_preprocessor() for details.

add_write_preprocessor(image_uri: str = None, config: dict = None, fn: pinecone.functions.Function = None)

Adds a preprocessor to the “write” path of the graph.

See add_preprocessor() for details.

remove_postprocessor(name: str)

Removes a postprocessor.

remove_preprocessor(path: str, name: str)

Removes a preprocessor from the given path.

Parameters
  • path ({"read", "write"}) – the path in the graph to remove the preprocessor from

  • name (str) – name of the preprocessor to remove

remove_read_preprocessor(name: str)

Removes a preprocessor from the “read” path.

See remove_preprocessor() for details.

remove_write_preprocessor(name: str)

Removes a preprocessor from the “write” path.

See remove_preprocessor() for details.

class pinecone.graph.Graph(*args, **kwargs)

The graphical representation of a service.

name

Name of the service.

to_obj() → dict

Serializes specs.

classmethod from_obj(state_dict: dict) → pinecone.specs.service.Service

Returns a new graph from the graph spec.

dump(format: str = 'yaml') → str

Dumps the graph as yaml or json string.

Parameters

format (str, optional) – one of {“yaml”, “json”}, defaults to “yaml”.

Return type

str

to_graph() → networkx.classes.multidigraph.MultiDiGraph

Exports to a networkx graph.

Construct a multi directed graph. Add incoming traffic and outgoing traffic nodes to signify the traffic flow.

Returns

[description]

Return type

nx.MultiDiGraph

view()

Visualizes the graph in an iPython notebook.

Note

This method requires the graphviz package installed on your operating system.

class pinecone.functions.model.HubFunction(image: str, config: dict = None, **kwargs)

A special Pinecone Function that loads models from the Model Hub.

Parameters
  • image (str) – a Pinecone Model Hub docker image URI

  • config (dict, optional) – configurations for the model, defaults to None

async handle_msg(msg: core_pb2.Request, timeout: float = 30) → core_pb2.Request

Handles requests.