Quellcode durchsuchen

Make the update script shorter. (#4854)

### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.17.0
Kevin Hu vor 8 Monaten
Ursprung
Commit
0d3ed37b48
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden
3 geänderte Dateien mit 10 neuen und 6 gelöschten Zeilen
  1. 0
    3
      conf/mapping.json
  2. 6
    1
      graphrag/search.py
  3. 4
    2
      rag/utils/es_conn.py

+ 0
- 3
conf/mapping.json Datei anzeigen

@@ -5,9 +5,6 @@
"number_of_replicas": 0,
"refresh_interval": "1000ms"
},
"persistent" : {
"script.max_compilations_rate" : "200/10m"
},
"similarity": {
"scripted_sim": {
"type": "scripted",

+ 6
- 1
graphrag/search.py Datei anzeigen

@@ -244,11 +244,16 @@ class KGSearch(Dealer):
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:

+ 4
- 2
rag/utils/es_conn.py Datei anzeigen

@@ -367,11 +367,13 @@ class ESConnection(DocStoreConnection):
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.")

Laden…
Abbrechen
Speichern