feat: complete KM-RAG polyglot ingestion pipeline migration
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NexusReader.Domain.Entities;
|
||||
using Pgvector;
|
||||
|
||||
|
||||
namespace NexusReader.Data.Persistence;
|
||||
|
||||
@@ -52,59 +50,24 @@ public class AppDbContext : IdentityDbContext<NexusUser>
|
||||
entity.HasIndex(p => p.PlanName).IsUnique();
|
||||
});
|
||||
|
||||
if (Database.IsSqlite())
|
||||
modelBuilder.Entity<SemanticKnowledgeCache>(entity =>
|
||||
{
|
||||
var vectorConverter = new Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter<Vector, string>(
|
||||
v => v != null ? string.Join(",", v.ToArray()) : string.Empty,
|
||||
s => !string.IsNullOrEmpty(s) ? new Vector(s.Split(',').Select(float.Parse).ToArray()) : null!
|
||||
);
|
||||
|
||||
modelBuilder.Entity<SemanticKnowledgeCache>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.ContentHash);
|
||||
entity.HasIndex(e => e.ContentHash).IsUnique();
|
||||
entity.HasIndex(e => e.TenantId);
|
||||
entity.Property(e => e.Vector).HasConversion(vectorConverter);
|
||||
});
|
||||
entity.HasKey(e => e.ContentHash);
|
||||
entity.HasIndex(e => e.ContentHash).IsUnique();
|
||||
entity.HasIndex(e => e.TenantId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<KnowledgeUnit>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.HasIndex(e => e.TenantId);
|
||||
entity.HasIndex(e => e.EbookId);
|
||||
entity.Property(e => e.Vector).HasConversion(vectorConverter);
|
||||
|
||||
entity.HasOne(e => e.Ebook)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.EbookId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
}
|
||||
else
|
||||
modelBuilder.Entity<KnowledgeUnit>(entity =>
|
||||
{
|
||||
modelBuilder.HasPostgresExtension("vector");
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.HasIndex(e => e.TenantId);
|
||||
entity.HasIndex(e => e.EbookId);
|
||||
|
||||
modelBuilder.Entity<SemanticKnowledgeCache>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.ContentHash);
|
||||
entity.HasIndex(e => e.ContentHash).IsUnique();
|
||||
entity.HasIndex(e => e.TenantId);
|
||||
entity.Property(e => e.Vector).HasColumnType("vector(1536)");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<KnowledgeUnit>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.HasIndex(e => e.TenantId);
|
||||
entity.HasIndex(e => e.EbookId);
|
||||
entity.Property(e => e.Vector).HasColumnType("vector(768)");
|
||||
|
||||
entity.HasOne(e => e.Ebook)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.EbookId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
}
|
||||
entity.HasOne(e => e.Ebook)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.EbookId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<KnowledgeUnitLink>(entity =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user