The HeliconeManualLogger class can be used to log any Vector DB interactions to Helicone.

1

To get started, install the `@helicone/helpers` package

npm install @helicone/helpers
2

Set `HELICONE_API_KEY` as an environment variable

export HELICONE_API_KEY=sk-<your-api-key>
You can also set the Helicone API Key in your code (See below)
3

Create a new HeliconeManualLogger instance

import { HeliconeManualLogger } from "@helicone/helpers";

const heliconeLogger = new HeliconeManualLogger({
  apiKey: process.env.HELICONE_API_KEY, // Can be set as env variable
  headers: {} // Additional headers to be sent with the request
});
4

Log your request

const res = await heliconeLogger.logRequest(
  {
    _type: "vector_db",
    operation: "search",
    // other data about the vector db request here (look at the API reference for more details)
  },
  async (resultRecorder) => {
    // your vector db operation here
    resultRecorder.appendResults({
      ... // The results of the operation (this will be logged to Helicone)
    });
    return results; // this will be returned by the logRequest function
  },
  {
   // Additional headers to be sent with the request
  }
);

API Reference

HeliconeManualLogger

class HeliconeManualLogger {
  constructor(opts: IHeliconeManualLogger)
}

type IHeliconeManualLogger = {
  apiKey: string;
  headers?: Record<string, string>;
  loggingEndpoint?: string; // defaults to https://api.hconeai.com/custom/v1/log
};

logRequest

logRequest<T>(
    request: HeliconeLogRequest,
    operation: (resultRecorder: HeliconeResultRecorder) => Promise<T>,
    additionalHeaders?: Record<string, string>
  ): Promise<T>

Parameters

  1. request: HeliconeLogRequest - The request object to log
type HeliconeLogRequest = ILogRequest | HeliconeCustomEventRequest;
type HeliconeCustomEventRequest = HeliconeEventTool | HeliconeEventVectorDB;

// the following is the type for the request object for vector db logging
interface HeliconeEventVectorDB {
  _type: "vector_db";
  operation: "search" | "insert" | "delete" | "update";
  text?: string;
  vector?: number[];
  topK?: number;
  filter?: object;
  databaseName?: string;
  [key: string]: any;
}
  1. operation: (resultRecorder: HeliconeResultRecorder) => Promise<T> - The operation to be executed and logged
class HeliconeResultRecorder {
  private results: Record<string, any> = {};

  appendResults(data: Record<string, any>): void {
    this.results = { ...this.results, ...data };
  }

  getResults(): Record<string, any> {
    return this.results;
  }
}
  1. additionalHeaders: Record<string, string>