Skip to content

Commit

Permalink
Make the update script shorter. (#4854)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
KevinHuSh authored Feb 10, 2025
1 parent bc68f18 commit 0d3ed37
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 0 additions & 3 deletions conf/mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"number_of_replicas": 0,
"refresh_interval": "1000ms"
},
"persistent" : {
"script.max_compilations_rate" : "200/10m"
},
"similarity": {
"scripted_sim": {
"type": "scripted",
Expand Down
7 changes: 6 additions & 1 deletion graphrag/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,16 @@ def retrieval(self, question: str,
else:
continue
rel["description"] = rela["description"]
desc = rel["description"]
try:
desc = json.loads(desc).get("description", "")
except Exception:
pass
relas.append({
"From Entity": f,
"To Entity": t,
"Score": "%.2f" % (rel["sim"] * rel["pagerank"]),
"Description": json.loads(rel["description"]).get("description", "")
"Description": desc
})
max_token -= num_tokens_from_string(str(relas[-1]))
if max_token <= 0:
Expand Down
6 changes: 4 additions & 2 deletions rag/utils/es_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,13 @@ def update(self, condition: dict, newValue: dict, indexName: str, knowledgebaseI
continue
if isinstance(v, str):
v = re.sub(r"(['\n\r]|\\.)", " ", v)
scripts.append(f"ctx._source.{k}='{v}';")
params[f"pp_{k}"] = v
scripts.append(f"ctx._source.{k}=params.pp_{k};")
elif isinstance(v, int) or isinstance(v, float):
scripts.append(f"ctx._source.{k}={v};")
elif isinstance(v, list):
scripts.append(f"ctx._source.{k}={json.dumps(v, ensure_ascii=False)};")
scripts.append(f"ctx._source.{k}=params.pp_{k};")
params[f"pp_{k}"] = json.dumps(v, ensure_ascii=False)
else:
raise Exception(
f"newValue `{str(k)}={str(v)}` value type is {str(type(v))}, expected to be int, str.")
Expand Down

0 comments on commit 0d3ed37

Please sign in to comment.