PipelineRun class - Pinecone handler
- TypeScript
- Python
The PipelineRun
class instance exposes a Pinecone handler that simplifies capturing generative output in Gentrace.
For a guided walkthrough of the Gentrace Pinecone integration, visit our quickstart here.
Usage
When the PipelineRun
instance is created, you can create a handle in two different ways to communicate with Pinecone.
Simple
Creating a simple handle is the easiest way to get started.
typescript
import {init ,Pipeline } from "@gentrace/core";import {Pinecone } from "@gentrace/pinecone";import {DEFAULT_VECTOR } from "../constants";init ({apiKey :process .env .GENTRACE_API_KEY });constpinecone = newPinecone ({apiKey :process .env .PINECONE_API_KEY !,});constindex = awaitpinecone .Index ("openai-trec");constqueryResponse = awaitindex .query ({includeValues : true,topK : 3,vector :DEFAULT_VECTOR ,pipelineSlug : "pinecone-example",});console .log ("queryResponse",queryResponse );
Creating a simple handle is the easiest way to get started. By invoking gentrace.configure_pinecone()
, we configure the
Gentrace SDK to automatically capture telemetry from Pinecone calls.
python
import osimport gentraceimport pinecone# TODO: Replace with your own vectorfrom my_vectors import DEFAULT_VECTORgentrace.init(api_key=os.getenv("GENTRACE_API_KEY"),)gentrace.configure_pinecone()pinecone.init(api_key=os.getenv("PINECONE_API_KEY"),)result = pinecone.Index("my-index").query(top_k=10, vector=DEFAULT_VECTOR, pipeline_slug="example-pipeline")
Advanced
The more advanced way involves creating a handle that is bound to a PipelineRun
instance. This allows you to attach
multiple steps to a single PipelineRun
instance.
typescript
construnner =pipeline .start ();constpinecone =runner .pinecone ;constindex = awaitpinecone .Index ("openai-trec");constqueryResponse = awaitindex .query ({includeValues : true,topK : 3,vector :DEFAULT_VECTOR ,});awaitrunner .submit ();
python
import osimport gentrace# TODO: Replace with your own vectorfrom my_vectors import DEFAULT_VECTORgentrace.init(api_key=os.getenv("GENTRACE_API_KEY"),)pipeline = gentrace.Pipeline("example-pipeline",pinecone_config={"api_key": os.getenv("PINECONE_API_KEY"),},)runner = pipeline.start()pinecone = runner.get_pinecone()index = pinecone.Index("my-index")result = index.query(top_k=10,vector=DEFAULT_VECTOR,)result.submit()
Fetch
The Index.fetch()
method is a wrapper around the equivalent Pinecone SDK method.
Arguments
The original Index.fetch()
method parameters are supported. The below key/value pairs overwrite
or augment the default key/value pairs for the options
object in the first parameter.
If you're using the Simple SDK, you can specify the pipeline slug here. If you're using the Advanced SDK, this is
set in the Pipeline
constructor and must be omitted.
gentrace
This object contains Gentrace context. Learn about context here.
Return value
The return value is a Promise
that resolves to the original OpenAI response. If you're using the simple SDK, the
response is augmented with a pipelineRunId
that references the run.
pipelineRunId?
The pipelineRunId
is a unique identifier for the run. It can be used to retrieve the run later.
Examples
typescript
construnner =pipeline .start ();constpinecone =runner .pinecone ;constindex = awaitpinecone .index ("my-index");constresponse = awaitindex .fetch (["8248"], {gentrace : {metadata : {gitSha : {type : "string",value : "6cb2a7e4f5765d92d95728f1746b9a1a59d8ad13"}}}});awaitrunner .submit ();
python
import osimport gentracegentrace.init(api_key=os.getenv("GENTRACE_API_KEY"),)pipeline = gentrace.Pipeline("example-pipeline",pinecone_config={"api_key": os.getenv("PINECONE_API_KEY"),},)pipeline.setup()runner = pipeline.start()pinecone = runner.get_pinecone()index = pinecone.Index("my-index")result = index.fetch(ids=["3980"], gentrace={"metadata": {"gitSha": {"type": "string","value": "6cb2a7e4f5765d92d95728f1746b9a1a59d8ad13"}}})runner.submit()
Upsert
The Index.upsert()
method is a wrapper around the equivalent Pinecone SDK method.
Arguments
The original Index.upsert()
method parameters are supported. The below key/value pairs overwrite or augment the defaults.
vectors
Same as the underlying Pinecone SDK, this parameter can be a single vector or an array of vectors that you want to upsert.
options
This object contain Gentrace-specific options.
pipelineSlug?
If you're using the Simple SDK, you can specify the pipeline slug here. If you're using the Advanced SDK, this is set in thePipeline
constructor and must be omitted.gentrace?
This object contains Gentrace context. Learn about context here.
The original Index.upsert()
method parameters are supported. The below keyword arguments overwrite or augment the
original keyword arguments.
vectors
Same as the underlying Pinecone SDK, this parameter can be a single vector or an array of vectors that you want to upsert.
pipeline_slug?
If you're using the Simple SDK, you can specify the pipeline slug here. If you're using the Advanced SDK, this is
set in the Pipeline
constructor and must be omitted.
gentrace?
This object contains Gentrace context. Learn about context here.
Return value
The return value is a Promise
that resolves to the original OpenAI response. If you're using the simple SDK, the
response is augmented with a pipelineRunId
that references the run.
pipelineRunId?
The pipelineRunId
is a unique identifier for the run. It can be used to retrieve the run later.
Examples
typescript
construnner =pipeline .start ();constpinecone =runner .pinecone ;constindex = awaitpinecone .index ("my-index");constupsert = awaitindex .upsert ([{id :String (Math .floor (Math .random () * 10000)),values :DEFAULT_VECTOR ,},]);awaitrunner .submit ();
python
import osimport randomimport gentracefrom examples.utils import DEFAULT_VECTORgentrace.init(api_key=os.getenv("GENTRACE_API_KEY"),)pipeline = gentrace.Pipeline("example-pipeline",pinecone_config={"api_key": os.getenv("PINECONE_API_KEY"),},)pipeline.setup()runner = pipeline.start()pinecone = runner.get_pinecone()index = pinecone.Index("my-index")result = index.upsert([{"id": str(random.randint(0, 9999)),"values": DEFAULT_VECTOR,},])runner.submit()
Query
The Index.query()
method is a wrapper around the equivalent Pinecone SDK method.
Arguments
The original Index.query()
method parameters are supported. The below key/value pairs overwrite of augment the defaults
for the first parameter.
If you're using the Simple SDK, you can specify the pipeline slug here. If you're using the Advanced SDK, this is
set in the Pipeline
constructor and must be omitted.
gentrace?
This object contains Gentrace context. Learn about context here.
Return value
The return value is a Promise
that resolves to the original OpenAI response. If you're using the simple SDK, the
response is augmented with a pipelineRunId
that references the run.
pipelineRunId?
The pipelineRunId
is a unique identifier for the run. It can be used to retrieve the run later.
Examples
typescript
construnner =pipeline .start ();constpinecone =runner .pinecone ;constindex = awaitpinecone .index ("my-index");constqueryResponse = awaitindex .query ({includeValues : true,topK : 3,vector :DEFAULT_VECTOR ,pipelineSlug : "pinecone-example",});awaitrunner .submit ();
python
import osimport gentracefrom examples.utils import DEFAULT_VECTORgentrace.init(api_key=os.getenv("GENTRACE_API_KEY"),)pipeline = gentrace.Pipeline("example-pipeline",pinecone_config={"api_key": os.getenv("PINECONE_API_KEY"),},)pipeline.setup()runner = pipeline.start()pinecone = runner.get_pinecone()index = pinecone.Index("openai-trec")result = index.query(top_k=10,vector=DEFAULT_VECTOR,)info = runner.submit()
Delete
The Index.deleteOne()
method is a wrapper around the equivalent Pinecone SDK method.
Arguments
The original Index.deleteOne()
method parameters are supported. The below key/value pairs overwrite or augment the defaults.
vectorId
Same as the underlying Pinecone SDK, this parameter is the ID of the vector you want to delete.
options
This object contain Gentrace-specific options.
pipelineSlug?
If you're using the Simple SDK, you can specify the pipeline slug here. If you're using the Advanced SDK, this is set in thePipeline
constructor and must be omitted.gentrace?
This object contains Gentrace context. Learn about context here.
The Index.delete()
method is a wrapper around the equivalent Pinecone SDK method.
Arguments
The original Index.delete()
method parameters are supported. The below keyword arguments overwrite or augment the defaults.
pipeline_slug?
If you're using the Simple SDK, you can specify the pipeline slug here. If you're using the Advanced SDK, this is
set in the Pipeline
constructor and must be omitted.
gentrace?
This object contains Gentrace context. Learn about context here.
Return value
The return value is a Promise
that resolves to the original OpenAI response. If you're using the simple SDK, the
response is augmented with a pipelineRunId
that references the run.
pipelineRunId?
The pipelineRunId
is a unique identifier for the run. It can be used to retrieve the run later.
Examples
typescript
construnner =pipeline .start ();constpinecone =runner .pinecone ;constindex = awaitpinecone .index ("my-index");constresponse = awaitindex .deleteOne ("8248");awaitrunner .submit ();
python
import osimport gentracegentrace.init(api_key=os.getenv("GENTRACE_API_KEY"),)pipeline = gentrace.Pipeline("example-pipeline",pinecone_config={"api_key": os.getenv("PINECONE_API_KEY"),},)runner = pipeline.start()pinecone = runner.get_pinecone()index = pinecone.Index("my-index")result = index.delete(ids=["3890"])info = runner.submit()