This commit is contained in:
2026-10-27 05:56:08 +03:30
parent 9e82e05bfe
commit 058d8da780
4 changed files with 172 additions and 1 deletions
+11
View File
@@ -26,7 +26,18 @@ namespace xAiApi.Constants
//
// Knowledge (Persistent RAG) ...
public const string XAiKnowledgeSeparator = "/";
public const string XAiKnowledgeOwnerSeparator = "/";
public const string XAiKnowledgeChunkSeparator = "#";
public const string XAiKnowledgeGlobalPrefix = "global";
public const string XAiKnowledgeProjectPrefix = "project";
public const string XAiKnowledgeConversationPrefix = "conversation";
//
// Knowledge Metadata Keys ...
public const string XAiKnowledgeMetadataType = "type";
public const string XAiKnowledgeMetadataScope = "scope";
public const string XAiKnowledgeMetadataScopeId = "scopeId";
public const string XAiKnowledgeMetadataOwnerId = "ownerId";
public const string XAiKnowledgeMetadataIngestedAtUtc = "ingestedAtUtc";
}
+12
View File
@@ -0,0 +1,12 @@
namespace xAiApi.Constants
{
/// <summary>
/// Knowledge Base Scope (Where Ingested Vectors are Visible) ...
/// </summary>
public enum XAiKnowledgeScope
{
Conversation = 0,
Project = 1,
Global = 2,
}
}
+27
View File
@@ -94,6 +94,16 @@ namespace xAiApi.Models
/// Short Snippet of Chunk Text ...
/// </summary>
public string Snippet { get; set; }
/// <summary>
/// Knowledge Scope the Chunk Retrieved from (Null for Session Based Documents) ...
/// </summary>
public string Scope { get; set; }
/// <summary>
/// Knowledge Type of the Chunk ...
/// </summary>
public string Type { get; set; }
}
/// <summary>
@@ -177,5 +187,22 @@ namespace xAiApi.Models
public string MetadataMimeType { get; set; } = "mimeType";
public string PromptName { get; set; } = "ChatWithDocuments";
public string MetadataChunkIndex { get; set; } = "chunkIndex";
//
// Knowledge (Persistent RAG) Limits ...
/// <summary>
/// Max Files Accepted in a Single Ingest Request (0 = Unlimited) ...
/// </summary>
public int MaxFilesPerIngest { get; set; } = 20;
/// <summary>
/// Max Size of a Single File in Bytes (0 = Unlimited) ...
/// </summary>
public long MaxFileSizeBytes { get; set; } = 25 * 1024 * 1024;
/// <summary>
/// Max Distinct Documents Allowed in a Non-Global Scope (0 = Unlimited) ...
/// </summary>
public int MaxDocumentsPerScope { get; set; } = 50;
}
}
+122 -1
View File
@@ -1,13 +1,75 @@
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>
@@ -36,6 +98,7 @@ namespace xAiApi.Models
/// <summary>
/// Ask Request over Persistent Knowledge Base ...
/// Retrieval is Tiered: Conversation -> Project -> Global (Each Tier Fills Remaining TopK) ...
/// </summary>
public class XAiKnowledgeAskRequest
{
@@ -45,7 +108,23 @@ namespace xAiApi.Models
public string Prompt { get; set; }
/// <summary>
/// Optional: Restrict Retrieval to a Specific File ...
/// 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; }
@@ -65,6 +144,21 @@ namespace xAiApi.Models
/// </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>
@@ -75,6 +169,11 @@ namespace xAiApi.Models
/// </summary>
public string MimeType { get; set; }
/// <summary>
/// Ingesting User Identifier ...
/// </summary>
public string OwnerId { get; set; }
/// <summary>
/// Count of Stored Chunks ...
/// </summary>
@@ -85,4 +184,26 @@ namespace xAiApi.Models
/// </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; }
}
}