Circle V2 API Docs
    Preparing search index...

    Function findRelevantDocumentsWithLLM

    • Parameters

      • options: {
            enableClassifyRetrievalMode?: boolean;
            model: ChatOpenAI;
            patientCharts?: {
                circle_metadata: Json;
                created_at: string;
                created_by: string | null;
                embedding_count: number | null;
                embedding_err_msg: string | null;
                embedding_status:
                    | "processing"
                    | "failed"
                    | "pending"
                    | "parse"
                    | "extract"
                    | "completed"
                    | null;
                entity_id: number
                | null;
                external_document_created_at: string | null;
                external_document_id: string | null;
                external_document_type:
                    | "kipu_evaluation"
                    | "kipu_consent_form"
                    | "kipu_ciwa_ar"
                    | "kipu_ciwa_b"
                    | "kipu_group_session"
                    | "lightningstep_formdata"
                    | "lightningstep_txplan"
                    | "kipu_vital_signs"
                    | "kipu_orthostatic_vital_signs"
                    | "kipu_patient_orders"
                    | "kipu_glucose_logs"
                    | "kipu_program_history"
                    | "kipu_diagnosis_history"
                    | "kipu_appointment"
                    | "lightningstep_admissions"
                    | "kipu_episode_outcome"
                    | "sunwave_form"
                    | "sunwave_diagnosis"
                    | "sunwave_group_note"
                    | "sunwave_program"
                    | "sunwave_lab_result"
                    | "sunwave_assessment"
                    | "emr_insurance_information"
                    | "insync_episode_summary"
                    | "insync_condition"
                    | "insync_vital_signs"
                    | "insync_lab_result"
                    | "insync_observation"
                    | "insync_allergy"
                    | "insync_immunization"
                    | "insync_medication_request"
                    | "insync_diagnostic_report"
                    | "insync_procedure"
                    | null;
                external_document_updated_at: string
                | null;
                file_name: string | null;
                file_type: "patient_chart" | "generated_form" | "emr_document" | null;
                file_url: string | null;
                id: number;
                integration_id: string | null;
                is_ready: boolean | null;
                patient_id: number | null;
                raw_document: Json;
                run_id: string | null;
                sources: Json;
                treatment_episode_id: string | null;
                updated_at: string | null;
            }[];
            patientId: number;
            question: string;
            supabase: SupabaseClient<Database>;
            treatmentEpisodeId?: string;
        }
        • OptionalenableClassifyRetrievalMode?: boolean
        • model: ChatOpenAI
        • OptionalpatientCharts?: {
              circle_metadata: Json;
              created_at: string;
              created_by: string | null;
              embedding_count: number | null;
              embedding_err_msg: string | null;
              embedding_status:
                  | "processing"
                  | "failed"
                  | "pending"
                  | "parse"
                  | "extract"
                  | "completed"
                  | null;
              entity_id: number
              | null;
              external_document_created_at: string | null;
              external_document_id: string | null;
              external_document_type:
                  | "kipu_evaluation"
                  | "kipu_consent_form"
                  | "kipu_ciwa_ar"
                  | "kipu_ciwa_b"
                  | "kipu_group_session"
                  | "lightningstep_formdata"
                  | "lightningstep_txplan"
                  | "kipu_vital_signs"
                  | "kipu_orthostatic_vital_signs"
                  | "kipu_patient_orders"
                  | "kipu_glucose_logs"
                  | "kipu_program_history"
                  | "kipu_diagnosis_history"
                  | "kipu_appointment"
                  | "lightningstep_admissions"
                  | "kipu_episode_outcome"
                  | "sunwave_form"
                  | "sunwave_diagnosis"
                  | "sunwave_group_note"
                  | "sunwave_program"
                  | "sunwave_lab_result"
                  | "sunwave_assessment"
                  | "emr_insurance_information"
                  | "insync_episode_summary"
                  | "insync_condition"
                  | "insync_vital_signs"
                  | "insync_lab_result"
                  | "insync_observation"
                  | "insync_allergy"
                  | "insync_immunization"
                  | "insync_medication_request"
                  | "insync_diagnostic_report"
                  | "insync_procedure"
                  | null;
              external_document_updated_at: string
              | null;
              file_name: string | null;
              file_type: "patient_chart" | "generated_form" | "emr_document" | null;
              file_url: string | null;
              id: number;
              integration_id: string | null;
              is_ready: boolean | null;
              patient_id: number | null;
              raw_document: Json;
              run_id: string | null;
              sources: Json;
              treatment_episode_id: string | null;
              updated_at: string | null;
          }[]

          Optional pre-fetched patient charts. When provided, skip the per-question Supabase fetch and filter in memory by the question's time filter. Caller is responsible for passing the full unfiltered set (or a superset covering the widest expected time window).

        • patientId: number
        • question: string
        • supabase: SupabaseClient<Database>
        • OptionaltreatmentEpisodeId?: string

          When set, the chart fetch is scoped to this treatment episode — the candidate set the LLM picks from contains ONLY that episode's charts, so cross-episode documents can never be considered. Has no effect when patientCharts is provided (the caller owns scoping in that case).

      Returns Promise<FindRelevantDocumentsResult>