mirror of
https://github.com/marcominerva/SqlDatabaseVectorSearch.git
synced 2026-06-20 12:23:10 +00:00
fa81f01c27
Updated `DocxContentDecoder`, `PdfContentDecoder`, and `TextContentDecoder` to return `Task<IEnumerable<Chunk>>` instead of `Task<string>`, introducing a new `Chunk` record for structured output. Restructured the `ApplicationDbContext`, `Document`, and `DocumentChunk` classes by moving them to the `SqlDatabaseVectorSearch.Data` namespace for better organization. Updated database migration files to align with the new entity structure and modified references in `Program.cs`, `DocumentService.cs`, and `VectorSearchService.cs` to use the new namespace.
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using EntityFramework.Exceptions.SqlServer;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SqlDatabaseVectorSearch.Data.Entities;
|
|
|
|
namespace SqlDatabaseVectorSearch.Data;
|
|
|
|
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : DbContext(options)
|
|
{
|
|
public virtual DbSet<Document> Documents { get; set; }
|
|
|
|
public virtual DbSet<DocumentChunk> DocumentChunks { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
base.OnConfiguring(optionsBuilder);
|
|
|
|
optionsBuilder.UseExceptionProcessor();
|
|
//optionsBuilder.EnableSensitiveDataLogging();
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<Document>(entity =>
|
|
{
|
|
entity.ToTable("Documents");
|
|
entity.HasKey(e => e.Id);
|
|
|
|
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
|
entity.Property(e => e.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(255);
|
|
});
|
|
|
|
modelBuilder.Entity<DocumentChunk>(entity =>
|
|
{
|
|
entity.ToTable("DocumentChunks");
|
|
entity.HasKey(e => e.Id);
|
|
|
|
entity.Property(e => e.Id).ValueGeneratedOnAdd();
|
|
entity.Property(e => e.Content).IsRequired();
|
|
entity.Property(e => e.Embedding)
|
|
.HasColumnType("vector(1536)")
|
|
.IsRequired();
|
|
|
|
entity.HasOne(d => d.Document).WithMany(p => p.Chunks)
|
|
.HasForeignKey(d => d.DocumentId)
|
|
.OnDelete(DeleteBehavior.Cascade)
|
|
.HasConstraintName("FK_DocumentChunks_Documents");
|
|
});
|
|
}
|
|
} |