Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langfuse Langfuse Comments Repository

From Leeroopedia
Knowledge Sources
Domains Repository, PostgreSQL, Comments
Last Updated 2026-02-14 00:00 GMT

Overview

PostgreSQL repository module that provides comment-based filtering queries, enabling users to filter traces, observations, sessions, and prompts by comment count or comment content using full-text search.

Description

This module provides two primary query functions for filtering objects based on their associated comments in the PostgreSQL database:

  • getObjectIdsByCommentCount: Queries for object IDs that have a specific number of comments matching a numeric comparison operator. Uses GROUP BY with HAVING COUNT(*) to efficiently filter by comment count. The operator is validated against a whitelist (>=, <=, =, >, <, !=) to prevent SQL injection.
  • getObjectIdsByCommentContent: Queries for object IDs where comment text matches a search query. For the contains operator, it leverages PostgreSQL's full-text search (to_tsvector / plainto_tsquery) with GIN index for optimal performance. For other operators (does not contain, starts with, ends with), it falls back to Prisma's query builder with case-insensitive ILIKE patterns.

Both functions are scoped by projectId and objectType (TRACE, OBSERVATION, SESSION, or PROMPT) and return arrays of matching object IDs.

The module also exports helper types: CommentObjectType, CommentCountOperator, and CommentContentOperator.

Usage

Use these functions when building table queries that need to filter by comment-related criteria (e.g., "show traces with at least 3 comments" or "show traces with comments containing 'bug'"). The returned object IDs are typically used as an additional filter condition in ClickHouse queries.

Code Reference

Source Location

Signature

export type CommentObjectType = "TRACE" | "OBSERVATION" | "SESSION" | "PROMPT";
export type CommentCountOperator = (typeof filterOperators.number)[number] | "!=";
export type CommentContentOperator = (typeof filterOperators.string)[number];

export async function getObjectIdsByCommentCount(params: {
  prisma: PrismaClient;
  projectId: string;
  objectType: CommentObjectType;
  operator: CommentCountOperator;
  value: number;
}): Promise<string[]>;

export async function getObjectIdsByCommentContent(params: {
  prisma: PrismaClient;
  projectId: string;
  objectType: CommentObjectType;
  searchQuery: string;
  operator?: CommentContentOperator;
}): Promise<string[]>;

Import

import {
  getObjectIdsByCommentCount,
  getObjectIdsByCommentContent,
  type CommentObjectType,
} from "@langfuse/shared/src/server/repositories/comments";

I/O Contract

Inputs

getObjectIdsByCommentCount

Name Type Required Description
prisma PrismaClient Yes Prisma client instance for PostgreSQL queries
projectId string Yes The project ID to scope the query
objectType CommentObjectType Yes The type of object to filter (TRACE, OBSERVATION, SESSION, PROMPT)
operator CommentCountOperator Yes Comparison operator for the count condition
value number Yes The count threshold to compare against

getObjectIdsByCommentContent

Name Type Required Description
prisma PrismaClient Yes Prisma client instance for PostgreSQL queries
projectId string Yes The project ID to scope the query
objectType CommentObjectType Yes The type of object to filter
searchQuery string Yes The text to search for in comment content
operator CommentContentOperator No Search operator; defaults to "contains"

Outputs

Name Type Description
(return) Promise<string[]> Array of object IDs matching the filter criteria

Usage Examples

import { getObjectIdsByCommentCount, getObjectIdsByCommentContent } from "./comments";

// Get traces with at least 3 comments
const tracesWithComments = await getObjectIdsByCommentCount({
  prisma,
  projectId: "proj-123",
  objectType: "TRACE",
  operator: ">=",
  value: 3,
});

// Get traces with comments containing "performance issue"
const tracesWithBugs = await getObjectIdsByCommentContent({
  prisma,
  projectId: "proj-123",
  objectType: "TRACE",
  searchQuery: "performance issue",
  operator: "contains",
});

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment