mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-24 17:50:04 +08:00
feat(vector-db): integrate vector database for image search
- Replace pgvector with Microsoft Vector DB for image vector storage and search - Update Picture model to use float[] instead of Vector type - Modify PictureService to use VectorDbService for vector search - Remove vector-related code from MyDbContext - Add PictureVector model for Vector DB integration
This commit is contained in:
@@ -2,7 +2,6 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json;
|
||||
using Foxel.Services.Attributes;
|
||||
using Vector = Pgvector.Vector;
|
||||
|
||||
namespace Foxel.Models.DataBase;
|
||||
|
||||
@@ -15,7 +14,7 @@ public class Picture : BaseModel
|
||||
[StringLength(1024)] public string? ThumbnailPath { get; set; } = string.Empty;
|
||||
|
||||
[StringLength(2000)] public string Description { get; set; } = string.Empty;
|
||||
[Column(TypeName = "vector(1024)")] public Vector? Embedding { get; set; }
|
||||
public float[]? Embedding { get; set; }
|
||||
|
||||
public DateTime? TakenAt { get; set; }
|
||||
|
||||
@@ -57,8 +56,8 @@ public enum PermissionType
|
||||
|
||||
public enum ProcessingStatus
|
||||
{
|
||||
Pending, // 等待处理
|
||||
Processing, // 处理中
|
||||
Completed, // 处理完成
|
||||
Failed // 处理失败
|
||||
Pending, // 等待处理
|
||||
Processing, // 处理中
|
||||
Completed, // 处理完成
|
||||
Failed // 处理失败
|
||||
}
|
||||
12
Models/Vector/PictureVector.cs
Normal file
12
Models/Vector/PictureVector.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Foxel.Models.Vector;
|
||||
|
||||
using Microsoft.Extensions.VectorData;
|
||||
|
||||
public class PictureVector
|
||||
{
|
||||
[VectorStoreKey] public int Id { get; set; }
|
||||
[VectorStoreData] public string? Name { get; set; }
|
||||
|
||||
[VectorStoreVector(Dimensions: 1024, DistanceFunction = DistanceFunction.CosineSimilarity)]
|
||||
public ReadOnlyMemory<float>? Embedding { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user