Browse Source

fix index params and add document title

nameczz 4 years ago
parent
commit
1ff06d163c

+ 1 - 0
.gitignore

@@ -32,6 +32,7 @@ server/dist
 server/build
 server/coverage
 server/documentation
+server/vectors.csv
 
 
 # package.lock.json

+ 1 - 1
client/src/components/insert/Import.tsx

@@ -160,7 +160,7 @@ const InsertImport: FC<InsertImportProps> = ({
             accept=".csv"
             setFileName={setFileName}
             handleUploadedData={handleUploadedData}
-            maxSize={parseByte('5m')}
+            maxSize={parseByte('150m')}
             overSizeWarning={insertTrans('overSizeWarning')}
           />
           <Typography className="text">

+ 6 - 0
client/src/context/Auth.tsx

@@ -36,6 +36,12 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
     check();
   }, [setAddress]);
 
+  useEffect(() => {
+    document.title = address
+      ? `Milvus Insight - ${address} `
+      : 'Milvus Insight';
+  }, [address]);
+
   return (
     <Provider value={{ isAuth, address, setAddress }}>
       {props.children}

+ 9 - 1
client/src/http/Index.ts

@@ -6,6 +6,8 @@ import {
 } from '../pages/schema/Types';
 import { ManageRequestMethods } from '../types/Common';
 import { IndexState } from '../types/Milvus';
+import { findKeyValue } from '../utils/Common';
+import { getKeyValueListFromJsonString } from '../utils/Format';
 import BaseModel from './BaseModel';
 
 export class IndexHttp extends BaseModel implements IndexView {
@@ -62,7 +64,13 @@ export class IndexHttp extends BaseModel implements IndexView {
   }
 
   get _indexParameterPairs() {
-    return this.params.filter(p => p.key !== 'index_type');
+    const metricType = this.params.filter(v => v.key === 'metric_type');
+    // parms is json string, so we need parse it to key value array
+    const params = findKeyValue(this.params, 'params');
+    if (params) {
+      return [...metricType, ...getKeyValueListFromJsonString(params)];
+    }
+    return metricType;
   }
 
   get _fieldName() {

+ 13 - 4
client/src/pages/schema/Create.tsx

@@ -57,6 +57,14 @@ const CreateIndex = (props: {
     [indexSetting.index_type, fieldType]
   );
 
+  const indexParams = useMemo(() => {
+    const params: { [x: string]: string } = {};
+    indexCreateParams.forEach(v => {
+      params[v] = indexSetting[v];
+    });
+    return params;
+  }, [indexCreateParams, indexSetting]);
+
   const indexOptions = useMemo(() => {
     const type =
       fieldType === 'BinaryVector'
@@ -77,6 +85,7 @@ const CreateIndex = (props: {
   const { validation, checkIsValid, disabled, setDisabled, resetValidation } =
     useFormValidation(checkedForm);
 
+  // reset index params
   useEffect(() => {
     setDisabled(true);
     setIndexSetting(v => ({
@@ -123,10 +132,10 @@ const CreateIndex = (props: {
         key: 'metric_type',
         value: metric_type,
       },
-      ...indexCreateParams.map(p => ({
-        key: p,
-        value: indexSetting[p],
-      })),
+      {
+        key: 'params',
+        value: JSON.stringify(indexParams),
+      },
     ];
 
     handleCreate(params);

+ 1 - 0
client/src/pages/schema/Schema.tsx

@@ -99,6 +99,7 @@ const Schema: FC<{
 
       try {
         const list = await fetchSchemaListWithIndex(collectionName);
+        console.log(list);
         const fields: FieldView[] = list.map(f =>
           Object.assign(f, {
             _fieldNameElement: (

+ 11 - 0
client/src/utils/Common.ts

@@ -33,3 +33,14 @@ export const formatNumber = (number: number): string => {
 export const throwErrorForDev = (text: string) => {
   throw new Error(text);
 };
+
+/**
+ *
+ * @param obj key value pair Array
+ * @param key the target you want to find.
+ * @returns undefined | string
+ */
+export const findKeyValue = (
+  obj: { key: string; value: string }[],
+  key: string
+) => obj.find(v => v.key === key)?.value;

+ 4 - 4
client/src/utils/Format.ts

@@ -74,11 +74,11 @@ export const getEnumKeyByValue = (enumObj: any, enumValue: any) => {
   return '--';
 };
 
-export const getKeyValueListFromJSON = (
-  paramJSON: string
+export const getKeyValueListFromJsonString = (
+  json: string
 ): { key: string; value: string }[] => {
   try {
-    const obj = JSON.parse(paramJSON);
+    const obj = JSON.parse(json);
 
     const pairs: { key: string; value: string }[] = Object.entries(obj).map(
       ([key, value]) => ({
@@ -116,4 +116,4 @@ export const getCreateFieldType = (config: Field): CreateFieldType => {
 };
 
 // Trim the address
-export const formatAddress = (address: string): string => address.trim();
+export const formatAddress = (address: string): string => address.trim();

+ 33 - 0
server/generate-csv.ts

@@ -0,0 +1,33 @@
+import { createObjectCsvWriter as createCsvWriter } from 'csv-writer';
+
+// use to test vector insert
+const csvWriter = createCsvWriter({
+  path: './vectors.csv',
+  header: [
+    { id: 'vector', title: 'vector' },
+    { id: 'age', title: 'age' },
+  ],
+});
+
+const records = [];
+
+const generateVector = (dimension) => {
+  let index = 0;
+  const vectors = [];
+  while (index < dimension) {
+    vectors.push(1 + Math.random());
+    index++;
+  }
+  return JSON.stringify(vectors);
+};
+
+while (records.length < 50000) {
+  const value = generateVector(128);
+  records.push({ vector: value, age: 10 });
+}
+
+csvWriter
+  .writeRecords(records) // returns a promise
+  .then(() => {
+    console.log('...Done');
+  });

+ 2 - 1
server/package.json

@@ -30,7 +30,7 @@
     "@nestjs/swagger": "^4.8.0",
     "@types/passport-jwt": "^3.0.5",
     "@types/passport-local": "^1.0.33",
-    "@zilliz/milvus2-sdk-node": "^1.0.2",
+    "@zilliz/milvus2-sdk-node": "^1.0.3",
     "body-parser": "^1.19.0",
     "class-transformer": "^0.4.0",
     "class-validator": "^0.13.1",
@@ -52,6 +52,7 @@
     "@types/supertest": "^2.0.10",
     "@typescript-eslint/eslint-plugin": "^4.19.0",
     "@typescript-eslint/parser": "^4.19.0",
+    "csv-writer": "^1.6.0",
     "eslint": "^7.22.0",
     "eslint-config-prettier": "^8.1.0",
     "eslint-plugin-prettier": "^3.3.1",

+ 1 - 1
server/src/main.ts

@@ -18,7 +18,7 @@ async function bootstrap() {
     .build();
   const document = SwaggerModule.createDocument(app, config);
   SwaggerModule.setup('api', app, document);
-  app.use(json({ limit: '50mb' }));
+  app.use(json({ limit: '150mb' }));
 
   await app.listen(port);
   Logger.log(`Milvus insight API server is running on port ${port}`);

+ 9 - 4
server/yarn.lock

@@ -1292,10 +1292,10 @@
   resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
   integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
 
-"@zilliz/milvus2-sdk-node@^1.0.2":
-  version "1.0.2"
-  resolved "https://registry.yarnpkg.com/@zilliz/milvus2-sdk-node/-/milvus2-sdk-node-1.0.2.tgz#68aecdaa9d2f27058d9af8322e3fc7acaf31da1e"
-  integrity sha512-Uwz0OZqvu8hcaoUU5xXKkJpgx2xwDttzCJihqttB4iTMrn7HERZeFJZLYgeL3BbxdEgKF0jbxGlstZ2kUWx9fQ==
+"@zilliz/milvus2-sdk-node@^1.0.3":
+  version "1.0.3"
+  resolved "https://registry.yarnpkg.com/@zilliz/milvus2-sdk-node/-/milvus2-sdk-node-1.0.3.tgz#909f1b44f5a7dedcfc3d075180f0273e8ace90f1"
+  integrity sha512-jAc/l7siEyNcDJ/WJ5tvbD/9bPMKXNWXCXaeUgLWLTitSrmjRLquhHKkf66OUU+rbEiDQw0l408jQyyY3CIZwA==
   dependencies:
     "@grpc/grpc-js" "^1.2.12"
     "@grpc/proto-loader" "^0.6.0"
@@ -2104,6 +2104,11 @@ cssstyle@^2.3.0:
   dependencies:
     cssom "~0.3.6"
 
+csv-writer@^1.6.0:
+  version "1.6.0"
+  resolved "https://registry.yarnpkg.com/csv-writer/-/csv-writer-1.6.0.tgz#d0cea44b6b4d7d3baa2ecc6f3f7209233514bcf9"
+  integrity sha512-NOx7YDFWEsM/fTRAJjRpPp8t+MKRVvniAg9wQlUKx20MFrPs73WLJhFf5iteqrxNYnsy924K3Iroh3yNHeYd2g==
+
 data-urls@^2.0.0:
   version "2.0.0"
   resolved "https://registry.yarnpkg.com/data-urls/-/data-urls-2.0.0.tgz#156485a72963a970f5d5821aaf642bef2bf2db9b"