UNPKG

graphzep

Version:

GraphZep: A temporal knowledge graph memory system for AI agents based on the Zep paper

77 lines (76 loc) 2.62 kB
/** * SPARQL Interface for GraphZep with full SPARQL 1.1 support * Provides high-level query interface with Zep-specific extensions */ import { OptimizedRDFDriver } from '../drivers/rdf-driver.js'; import { NamespaceManager } from './namespaces.js'; import { ZepMemory, ZepFact, ZepSearchParams, ZepSearchResult, MemoryType } from '../zep/types.js'; export interface SPARQLQueryOptions { timeout?: number; limit?: number; offset?: number; orderBy?: string; descending?: boolean; temporalFilter?: TemporalFilter; confidenceThreshold?: number; includeInferred?: boolean; } export interface TemporalFilter { type: 'at' | 'between' | 'before' | 'after' | 'during'; timestamp?: Date; startTime?: Date; endTime?: Date; validityCheck?: boolean; } export interface SPARQLQueryResult { bindings: Record<string, any>[]; count: number; executionTime: number; cached: boolean; } export declare class ZepSPARQLInterface { private driver; private nsManager; constructor(driver: OptimizedRDFDriver, nsManager?: NamespaceManager); /** * Execute raw SPARQL query with automatic prefix addition */ query(sparqlQuery: string, options?: SPARQLQueryOptions): Promise<SPARQLQueryResult>; /** * Search memories using SPARQL with Zep-specific optimizations */ searchMemories(params: ZepSearchParams): Promise<ZepSearchResult[]>; /** * Get memories at a specific point in time */ getMemoriesAtTime(timestamp: Date, memoryTypes?: MemoryType[]): Promise<ZepMemory[]>; /** * Get facts about entities with temporal constraints */ getFactsAboutEntity(entityName: string, validAt?: Date): Promise<ZepFact[]>; /** * Find related entities using graph traversal */ findRelatedEntities(entityName: string, maxHops?: number, minConfidence?: number): Promise<any[]>; /** * Aggregate memories by session with statistics */ getSessionSummary(sessionId: string): Promise<any>; /** * Complex analytical query: Memory evolution over time */ getMemoryEvolution(timeWindow?: 'day' | 'week' | 'month', limit?: number): Promise<any[]>; /** * Advanced reasoning query: Infer contradictions */ findContradictions(confidenceThreshold?: number): Promise<any[]>; private addZepPrefixes; private applyQueryOptions; private addTemporalFilter; private buildMemorySearchQuery; private formatSearchResults; private formatMemoryResults; private formatFactResults; private bindingToMemory; private parseMemoryType; }