feat: implement semantic search, knowledge unit extraction, and visualization components
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using NexusReader.Domain.Enums;
|
||||
|
||||
namespace NexusReader.Domain.Entities;
|
||||
|
||||
public class KnowledgeUnit
|
||||
{
|
||||
[Key]
|
||||
[MaxLength(128)]
|
||||
public string Id { get; set; } = string.Empty; // Hash(Source + Content + Version)
|
||||
|
||||
[Required]
|
||||
[MaxLength(128)]
|
||||
public string SourceId { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(50)]
|
||||
public string Version { get; set; } = "1.0";
|
||||
|
||||
[Required]
|
||||
public KnowledgeUnitType Type { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
public string? MetadataJson { get; set; } // e.g. { "page": 1, "path": "Chapter 1 > Intro" }
|
||||
|
||||
[Required]
|
||||
[MaxLength(128)]
|
||||
public string TenantId { get; set; } = string.Empty;
|
||||
|
||||
[Column(TypeName = "vector(768)")] // Default for text-embedding-004
|
||||
public float[]? Vector { get; set; }
|
||||
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
// Relationships
|
||||
public ICollection<KnowledgeUnitLink> OutgoingLinks { get; set; } = new List<KnowledgeUnitLink>();
|
||||
public ICollection<KnowledgeUnitLink> IncomingLinks { get; set; } = new List<KnowledgeUnitLink>();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace NexusReader.Domain.Entities;
|
||||
|
||||
public class KnowledgeUnitLink
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(128)]
|
||||
public string SourceUnitId { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(128)]
|
||||
public string TargetUnitId { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(50)]
|
||||
public string RelationType { get; set; } = "References"; // e.g., "Next", "Defines", "Contains"
|
||||
|
||||
[ForeignKey(nameof(SourceUnitId))]
|
||||
public KnowledgeUnit SourceUnit { get; set; } = null!;
|
||||
|
||||
[ForeignKey(nameof(TargetUnitId))]
|
||||
public KnowledgeUnit TargetUnit { get; set; } = null!;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace NexusReader.Domain.Entities;
|
||||
|
||||
@@ -11,6 +12,9 @@ public class SemanticKnowledgeCache
|
||||
[Required]
|
||||
public string JsonData { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string OriginalText { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[MaxLength(50)]
|
||||
public string ModelId { get; set; } = "gemini-1.5-flash";
|
||||
@@ -19,5 +23,12 @@ public class SemanticKnowledgeCache
|
||||
[MaxLength(10)]
|
||||
public string PromptVersion { get; set; } = "1.0";
|
||||
|
||||
[Required]
|
||||
[MaxLength(128)]
|
||||
public string TenantId { get; set; } = string.Empty;
|
||||
|
||||
[Column(TypeName = "vector(1536)")] // text-embedding-004 has 768 or 1536 dims, assuming 1536 for high-fidelity
|
||||
public float[]? Vector { get; set; }
|
||||
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace NexusReader.Domain.Enums;
|
||||
|
||||
public enum KnowledgeUnitType
|
||||
{
|
||||
Section,
|
||||
Table,
|
||||
Definition,
|
||||
ProcedureStep,
|
||||
PolicyRule,
|
||||
KeyConcept,
|
||||
Snippet
|
||||
}
|
||||
Reference in New Issue
Block a user