private static int TrainDemo() { // 训练demo var handle = IntPtr.Zero; var ret = CsCaiss.CreateHandle(ref handle); if (CsCaissDefine.CAISS_RET_OK != ret) { return(ret); } ret = CsCaiss.Init(handle, CsCaissDefine.CAISS_MODE.CAISS_MODE_TRAIN, CsCaissDefine.CAISS_DISTANCE_TYPE.CAISS_DISTANCE_INNER, DIM, MODEL_PATH); if (CsCaissDefine.CAISS_RET_OK != ret) { return(ret); } ret = CsCaiss.Train(handle, DATA_PATH, MAX_DATA_SIZE, NORMALIZE, MAX_INDEX_SIZE, PRECISION, FAST_RANK, REAL_RANK, STEP, MAX_EPOCH, SHOW_SPAN); if (CsCaissDefine.CAISS_RET_OK != ret) { return(ret); } return(CsCaiss.DestroyHandle(handle)); }
private static int SearchDemo() { // 查询demo var handle = IntPtr.Zero; var ret = CsCaiss.CreateHandle(ref handle); if (CsCaissDefine.CAISS_RET_OK != ret) { return(ret); } ret = CsCaiss.Init(handle, CsCaissDefine.CAISS_MODE.CAISS_MODE_PROCESS, CsCaissDefine.CAISS_DISTANCE_TYPE.CAISS_DISTANCE_INNER, DIM, MODEL_PATH); if (CsCaissDefine.CAISS_RET_OK != ret) { return(ret); } int status = 0; string result = CsCaiss.SyncSearch(handle, QUERY_WORD, CsCaissDefine.CAISS_SEARCH_TYPE.CAISS_SEARCH_WORD, TOP_K, FILTER_EDIT_DISTANCE, ref status); //var result = CsCaiss.SyncExecuteSQL(handle, QUERY_SQL, ref status); // sql方式查询 if (CsCaissDefine.CAISS_RET_OK != status) { ret = status; return(ret); } Console.WriteLine(result); // 打印输出的结果信息 return(CsCaiss.DestroyHandle(handle)); }
private static string getResultString(IntPtr handle, ref int status) { // 获取结果信息 uint size = 0; var ret = CsCaiss.GetResultSize(handle, ref size); if (CsCaissDefine.CAISS_RET_OK != ret) { status = ret; return(""); } var resultPtr = Marshal.AllocHGlobal((int)size + 1); // 申请内存 Marshal.WriteByte(resultPtr, 0); ret = CsCaiss.GetResult(handle, resultPtr, size); var result = Marshal.PtrToStringAnsi(resultPtr); // 获取返回的结果字符串 Marshal.FreeHGlobal(resultPtr); // 释放内存信息 if (CsCaissDefine.CAISS_RET_OK != ret) { status = ret; return(""); } return(result); }
public static void Main(string[] args) { // 初始化caiss环境 var ret = CsCaiss.Environment(MAX_THREAD_SIZE, CsCaissDefine.CAISS_ALGO_TYPE.CAISS_ALGO_HNSW, CsCaissDefine.CAISS_MANAGE_TYPE.CAISS_MANAGE_SYNC); if (CsCaissDefine.CAISS_RET_OK != ret) { // caiss环境初始化异常 return; } // ret = TrainDemo(); // Console.WriteLine("train demo ret is : {0}", ret); // 查看查询demo的返回值信息 // 查看训练demo的返回值信息 ret = SearchDemo(); Console.WriteLine("search demo ret is : {0}", ret); // 查看查询demo的返回值信息 }