pgvector可以出一个详细的教程吗? 返回

SqlSugar 沟通中
9 500

https://www.donet5.com/ask/9/23319这篇文章看完,还是不知道怎么处理,一头雾水!

热忱回答9

  • fate sta fate sta VIP0
    2024/4/29

    先学一下sqlsugar的自定义类型 

    0 回复
  • fate sta fate sta VIP0
    2024/4/29

    然后在学一下 PgVector 差不多就会了,我也没用过。都是用户用的

    0 回复
  • public class VectorConverter : ISugarDataConverter

    {

        public SugarParameter ParameterConverter<T>(object columnValue, int columnIndex)

        {

            var vector = columnValue as Vector;

            return new SugarParameter($"vector{columnIndex}", vector.ToString());

        }


        public T QueryConverter<T>(System.Data.IDataRecord dataRecord, int dataRecordIndex)

        {

            if (typeof(T).IsAssignableFrom(typeof(Vector)))

            {

                var str = dataRecord[dataRecordIndex];

                var vector = new Vector(str.ToString());

                return (T)Convert.ChangeType(vector, typeof(T));

            }

            else

            {

                throw Oops.Oh("无效的类型");

            }

        }

    }

    其中,Vector类型是 https://github.com/pgvector/pgvector-dotnet 这个包的!

    自定义类型的时候:var str = dataRecord[dataRecordIndex];提示错误

    The field 'vector' has type 'public.vector', which is currently unknown to Npgsql. You can retrieve it as a string by marking it as unknown, please see the FAQ.

    0 回复
  • 自定义类型的时候:var str = dataRecord[dataRecordIndex];提示错误

    The field 'vector' has type 'public.vector', which is currently unknown to Npgsql. You can retrieve it as a string by marking it as unknown, please see the FAQ.

    0 回复
  • 使用 https://github.com/pgvector/pgvector-dotnet

    var dataSourceBuilder = new NpgsqlDataSourceBuilder(connString);
    dataSourceBuilder.UseVector();
    await using var dataSource = dataSourceBuilder.Build();var conn = dataSource.OpenConnection();

    我看你在那一片帖子里边是说可以,可是,我不知道怎么写!

    这个代码要写在哪里呢?sqlsugar有提供吗?而且,它的npgsql包是8.0版本,比sqlsugar高

    0 回复
  • 现在都在弄AI知识库,向量存储pgvector还是挺方便的,应该很多人会有这个需求,希望能帮忙解决下!先谢谢了!

    0 回复
  • 找到一个别人封装好的:https://github.com/ZeekoZhu/dotnet-prelude/blob/main/libs/sql-sugar-pgvector.test/UnitTest1.cs

    0 回复
  • 用起来有点麻烦,别扭!

    0 回复
  • fate sta fate sta VIP0
    2024/4/30

    能用就可以了,这个我没有细研究过

    0 回复