{"record":{"id":"150a65e1a01b508e","repo":"NationalSecurityAgency/ghidra","slug":"weighttable-has-wrong-number-of-rows-150a65","errorCode":null,"errorMessage":"weighttable has wrong number of rows","messagePattern":"weighttable has wrong number of rows","errorType":"exception","errorClass":"ElasticException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java","lineNumber":2418,"sourceCode":"\t\tJsonObject index = (JsonObject) settings.get(\"index\");\n\t\tJsonObject analysis = (JsonObject) index.get(\"analysis\");\n\t\tJsonObject tokenizer = (JsonObject) analysis.get(\"tokenizer\");\n\t\tString tokenizerName = null;\n\t\tfor (String key : tokenizer.keySet()) {\n\t\t\tif (key.startsWith(\"lsh_\")) {\n\t\t\t\ttokenizerName = key;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (tokenizerName == null) {\n\t\t\tthrow new ElasticException(\"Missing tokenizer configuration\");\n\t\t}\n\t\tJsonObject tokenizerSettings = (JsonObject) tokenizer.get(tokenizerName);\n\t\tString idfWeights = tokenizerSettings.get(ElasticUtilities.LSH_WEIGHTS).getAsString();\n\t\tString[] split = idfWeights.split(\" \");\n\t\tdouble[] weightArray = new double[split.length];\n\t\tif (weightArray.length != config.weightfactory.getSize()) {\n\t\t\tthrow new ElasticException(\"weighttable has wrong number of rows\");\n\t\t}\n\t\tfor (int i = 0; i < weightArray.length; ++i) {\n\t\t\tweightArray[i] = Double.parseDouble(split[i]);\n\t\t}\n\t\tconfig.weightfactory.set(weightArray);\n\n\t\tString lookup = tokenizerSettings.get(ElasticUtilities.IDF_CONFIG).getAsString();\n\t\tsplit = lookup.split(\" \");\n\t\tint[] lookupArray = new int[split.length];\n\t\tfor (int i = 0; i < lookupArray.length; ++i) {\n\t\t\tlookupArray[i] = Integer.parseInt(split[i]);\n\t\t}\n\t\tconfig.idflookup.set(lookupArray);\n\t}\n\n\t@Override\n\tpublic Status getStatus() {\n\t\treturn status;","sourceCodeStart":2400,"sourceCodeEnd":2436,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java#L2400-L2436","documentation":"Thrown in initializeElastic when the number of IDF weights parsed from the LSH tokenizer's LSH_WEIGHTS setting does not equal config.weightfactory.getSize(). This signals a dimension mismatch between the feature-vector space the client expects and what the database was configured with. The weight table size is determined by the database settings value, so a mismatch means the client and database use incompatible settings.","triggerScenarios":"During initialize() -> initializeElastic, the LSH_WEIGHTS string from the tokenizer settings is split by spaces into weightArray. Its length is compared to config.weightfactory.getSize(); any difference triggers the exception.","commonSituations":"Client and database use different BSim settings values (the settings integer controls vector dimensions); version mismatch where a BSim upgrade changed the weight table size; database created with one settings value but the client computed a different one from its local configuration.","solutions":["Ensure the client's settings value matches the database's settings value stored in the configuration index (read via the settings key).","Use the same BSim version and configuration that created the database — check compareLayout() returns 0.","If a settings change is intentional, drop and recreate the database so the weight table is rebuilt consistently.","Inspect the LSH_WEIGHTS field in the vector tokenizer settings via curl to confirm the expected weight count."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify weight table dimensions match before initializing\nJsonObject settings = connection.executeURIOnly(ElasticConnection.GET, \"vector/_settings\");\n// Extract and parse LSH_WEIGHTS to check dimension\nint expectedSize = config.weightfactory.getSize();\n// Compare with stored weights count in tokenizer settings\nif (storedWeightCount != expectedSize) {\n    throw new IllegalStateException(\n        \"Weight table dimension mismatch: client expects \" + expectedSize + \", database has \" + storedWeightCount);\n}","typeGuard":null,"tryCatchPattern":"try {\n    database.initialize();\n} catch (ElasticException e) {\n    if (e.getMessage().equals(\"weighttable has wrong number of rows\")) {\n        Msg.error(this, \"Weight table dimension mismatch — client and database use incompatible settings: \" + e.getMessage());\n        // Use matching BSim version or recreate database\n    }\n    throw e;\n}","preventionTips":["Use the same BSim version and settings value for both database creation and querying.","Check compareLayout() and the settings configuration value before connecting.","If upgrading BSim, drop and recreate the database to rebuild the weight table consistently."],"tags":["elasticsearch","bsim","version-mismatch","configuration","weight-table","initialization"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}