Skip to main content
Version: 2.0.0

PipelineRun class - Pinecone handler

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
});
 
const pinecone = new Pinecone({
apiKey: process.env.PINECONE_API_KEY!,
});
 
const index = await pinecone.Index("openai-trec");
 
const queryResponse = await index.query({
includeValues: true,
topK: 3,
vector: DEFAULT_VECTOR,
pipelineSlug: "pinecone-example",
});
 
console.log("queryResponse", queryResponse);

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
const runner = pipeline.start();
 
const pinecone = runner.pinecone;
 
const index = await pinecone.Index("openai-trec");
 
const queryResponse = await index.query({
includeValues: true,
topK: 3,
vector: DEFAULT_VECTOR,
});
 
await runner.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.

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 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
const runner = pipeline.start();
 
const pinecone = runner.pinecone;
 
const index = await pinecone.index("my-index");
 
const response = await index.fetch(["8248"], {
gentrace: {
metadata: {
gitSha: {
type: "string",
value: "6cb2a7e4f5765d92d95728f1746b9a1a59d8ad13"
}
}
}
});
 
await 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 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
const runner = pipeline.start();
 
const pinecone = runner.pinecone;
 
const index = await pinecone.index("my-index");
 
const upsert = await index.upsert([
{
id: String(Math.floor(Math.random() * 10000)),
values: DEFAULT_VECTOR,
},
]);
 
await 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.

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 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
const runner = pipeline.start();
 
const pinecone = runner.pinecone;
 
const index = await pinecone.index("my-index");
 
const queryResponse = await index.query({
includeValues: true,
topK: 3,
vector: DEFAULT_VECTOR,
pipelineSlug: "pinecone-example",
});
 
await 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 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
const runner = pipeline.start();
 
const pinecone = runner.pinecone;
 
const index = await pinecone.index("my-index");
 
const response = await index.deleteOne("8248");
 
await runner.submit();