Files
xSaherElmAiApi/Models/XAiKnowledgeModels.cs
T
2026-10-27 05:56:08 +03:30

210 lines
6.0 KiB
C#

using xAiApi.Constants;
using xAiApi.Constants;
using System;
using xAiApi.Constants;
using System.Collections.Generic;
namespace xAiApi.Models
{
/// <summary>
/// Describes Target Knowledge Base Scope of an Operation ...
/// </summary>
public class XAiKnowledgeScopeDescriptor
{
/// <summary>
/// Scope Kind ...
/// </summary>
public XAiKnowledgeScope Scope { get; set; }
/// <summary>
/// Scope Identifier (ProjectId / ConversationId) - Null for Global ...
/// </summary>
public Guid? ScopeId { get; set; }
/// <summary>
/// Optional Knowledge Type / Domain Filter ...
/// </summary>
public string Type { get; set; }
//
public static XAiKnowledgeScopeDescriptor Global(string type = null) => new()
{
Type = type,
ScopeId = null,
Scope = XAiKnowledgeScope.Global,
};
public static XAiKnowledgeScopeDescriptor Project(Guid projectId, string type = null) => new()
{
Type = type,
ScopeId = projectId,
Scope = XAiKnowledgeScope.Project,
};
public static XAiKnowledgeScopeDescriptor Conversation(Guid conversationId, string type = null) => new()
{
Type = type,
ScopeId = conversationId,
Scope = XAiKnowledgeScope.Conversation,
};
}
/// <summary>
/// Result of Ingesting Files into Persistent Knowledge Base (XAiVector Table) ...
/// </summary>
public class XAiKnowledgeIngestResult
{
/// <summary>
/// Target Scope ...
/// </summary>
public XAiKnowledgeScope Scope { get; set; }
/// <summary>
/// Target Scope Identifier (Null for Global) ...
/// </summary>
public Guid? ScopeId { get; set; }
/// <summary>
/// Knowledge Type of Ingested Vectors ...
/// </summary>
public string Type { get; set; }
/// <summary>
/// Count of Successfully Ingested Files ...
/// </summary>
public int FilesCount { get; set; }
/// <summary>
/// Count of Stored Chunks (Vectors) in this Request ...
/// </summary>
public int ChunksCount { get; set; }
/// <summary>
/// Count of Removed Stale Vectors (Re-Ingest) ...
/// </summary>
public int ReplacedCount { get; set; }
/// <summary>
/// Skipped Files (Empty, Unsupported or Extraction Failed) ...
/// </summary>
public IList<string> SkippedFiles { get; set; } = new List<string>();
/// <summary>
/// Ingested Documents Info ...
/// </summary>
public IList<XAiKnowledgeDocumentInfo> Documents { get; set; } = new List<XAiKnowledgeDocumentInfo>();
}
/// <summary>
/// Ask Request over Persistent Knowledge Base ...
/// Retrieval is Tiered: Conversation -> Project -> Global (Each Tier Fills Remaining TopK) ...
/// </summary>
public class XAiKnowledgeAskRequest
{
/// <summary>
/// Question ...
/// </summary>
public string Prompt { get; set; }
/// <summary>
/// Optional: Conversation Scope (Caller must be Conversation Owner) ...
/// When Provided, Conversation's Project is used for Second Tier Automatically ...
/// </summary>
public Guid? ConversationId { get; set; }
/// <summary>
/// Optional: Project Scope (Caller must be Project Owner) ...
/// </summary>
public Guid? ProjectId { get; set; }
/// <summary>
/// Optional: Restrict Retrieval to a Knowledge Type / Domain ...
/// </summary>
public string Type { get; set; }
/// <summary>
/// Optional: Restrict Retrieval to a Specific File Name ...
/// </summary>
public string FileName { get; set; }
/// <summary>
/// Optional: Max Retrieved Chunks ...
/// </summary>
public int? TopK { get; set; }
/// <summary>
/// Optional: Minimum Cosine Similarity Score ...
/// </summary>
public float? MinScore { get; set; }
}
/// <summary>
/// Ingested Document Info ...
/// </summary>
public class XAiKnowledgeDocumentInfo
{
/// <summary>
/// Scope ...
/// </summary>
public XAiKnowledgeScope Scope { get; set; }
/// <summary>
/// Scope Identifier (Null for Global) ...
/// </summary>
public Guid? ScopeId { get; set; }
/// <summary>
/// Knowledge Type ...
/// </summary>
public string Type { get; set; }
/// <summary>
/// File Name ...
/// </summary>
public string FileName { get; set; }
/// <summary>
/// Mime Type ...
/// </summary>
public string MimeType { get; set; }
/// <summary>
/// Ingesting User Identifier ...
/// </summary>
public string OwnerId { get; set; }
/// <summary>
/// Count of Stored Chunks ...
/// </summary>
public int ChunksCount { get; set; }
/// <summary>
/// Ingestion Time (UTC) ...
/// </summary>
public DateTime? IngestedAtUtc { get; set; }
}
/// <summary>
/// Public Vector Info (Export) ...
/// </summary>
public class XAiKnowledgeVectorInfo
{
public Guid Id { get; set; }
public string Text { get; set; }
public string Type { get; set; }
public Guid? ScopeId { get; set; }
public string FileName { get; set; }
public int? ChunkIndex { get; set; }
public string Identifier { get; set; }
public XAiKnowledgeScope Scope { get; set; }
public Dictionary<string, string> Metadata { get; set; }
/// <summary>
/// Embedding (Only Filled when Requested) ...
/// </summary>
public float[] Embedding { get; set; }
}
}