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 Pinecone docs.
Usage
Create a handle in two ways to communicate with Pinecone.
Simple
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 !,environment :process .env .PINECONE_ENVIRONMENT !,});constindex = awaitpinecone .Index ("openai-trec");constqueryResponse = awaitindex .query ({includeValues : true,topK : 3,vector :DEFAULT_VECTOR ,pipelineSlug : "pinecone-example",});console .log ("queryResponse",queryResponse );
Invoke gentrace.configure_pinecone()
to 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 advanced method 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 below key-value pairs augment the defaults.
pipelineSlug?: string (UUID)
pipeline_slug?: str (UUID)
If you're using the Simple SDK, you can specify the pipeline slug here.
gentrace: object
This object contains Gentrace context. Learn about context here.
Return value
Resolves to the original Pinecone response. If you're using the simple SDK, the
response has an additional pipelineRunId
.
pipelineRunId?: string (UUID)
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"),},)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 below key-value pairs augment the defaults.
vectors: Vector[]
Same as the underlying Pinecone SDK, this parameter can be a single vector or an array of vectors that you want to upsert.
options: object
This object contain Gentrace-specific options.
pipelineSlug?
If you're using the Simple SDK, you can specify the pipeline slug here.gentrace?
This object contains Gentrace context. Learn about context here.
The below keyword arguments augment the original keyword arguments.
vectors: List
pipeline_slug?: str (UUID)
gentrace?
This object contains Gentrace context. Learn about context here.
Return value
Resolves to the original Pinecone response. If you're using the simple SDK, the
response has an additional pipelineRunId
.
pipelineRunId?: string (UUID)
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"),},)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 below key-value pairs augment the defaults for the first parameter.
pipelineSlug?: string
pipeline_slug?: str
If you're using the Simple SDK, you can specify the pipeline slug here.
gentrace?: object
This object contains Gentrace context. Learn about context here.
Return value
Resolves to the original Pinecone response. If you're using the simple SDK, the
response has an additional pipelineRunId
.
pipelineRunId?: string (UUID)
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"),},)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 below key-value pairs augment the defaults.
vectorId: string
Same as the underlying Pinecone SDK, this parameter is the ID of the vector you want to delete.
options: object
This object contain Gentrace-specific options.
pipelineSlug?: string
If you're using the Simple SDK, you can specify the pipeline slug here.gentrace?: object
This object contains Gentrace context. Learn about context here.
The Index.delete()
method is a wrapper around the equivalent Pinecone SDK method.
Arguments
The below keyword arguments augment the defaults.
pipeline_slug?: str
If you're using the Simple SDK, you can specify the pipeline slug here.
gentrace?: object
This object contains Gentrace context. Learn about context here.
Return value
Resolves to the original Pinecone response. If you're using the simple SDK, the
response has an additional pipelineRunId
.
pipelineRunId?: string (UUID)
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()