68 lines
1.7 KiB
Python
68 lines
1.7 KiB
Python
from dotenv import load_dotenv
|
|
import os
|
|
import sys
|
|
from app.common.elastic_helper import ElasticHelper
|
|
from elasticsearch.helpers import scan
|
|
from pathlib import Path
|
|
|
|
# sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
|
|
load_dotenv(dotenv_path=r"D:\init_mahdi\dataParsers\config.env")
|
|
|
|
host = os.getenv("HOST_99")
|
|
password = os.getenv("PASSWORD_99")
|
|
|
|
elastic = ElasticHelper(es_url=host, es_pass=password, es_user="elastic")
|
|
|
|
query1 = {
|
|
"_source": ["context"],
|
|
"query": {
|
|
"bool": {
|
|
"filter": [{"term": {"version_key": "base_v3"}}],
|
|
"must": [{"exists": {"field": "context"}}],
|
|
# "must_not": [{"exists": {"field": "embedding"}}],
|
|
}
|
|
},
|
|
}
|
|
|
|
|
|
query = {
|
|
"_source": ["content"],
|
|
"query": {
|
|
"bool": {
|
|
"filter": [{"term": {"version_key": "base_v3"}}],
|
|
"must_not": [
|
|
{"terms": {"title": ["موخره", "امضاء", "عنوان", "فصل", "مبحث"]}}
|
|
],
|
|
}
|
|
},
|
|
}
|
|
|
|
documents = [
|
|
# {
|
|
# "id": hit["_id"],
|
|
# "content": hit["_source"]["content"],
|
|
# "qanon_title":hit["_source"]["qanon_title"],
|
|
# "rule_type":hit["_source"]["rule_type"],
|
|
# }
|
|
|
|
hit
|
|
for hit in scan(
|
|
elastic.es, # اگر نام کلاینت داخل ElasticHelper چیز دیگری است، آن را جایگزین کنید
|
|
# index="majles_mj_qa_rule",
|
|
index="majles_mj_qa_context",
|
|
query=query1,
|
|
size=1000,
|
|
)
|
|
]
|
|
|
|
print(f"documents {len(documents)}")
|
|
|
|
elastic.save_orjson(
|
|
path=Path(r"D:\init_mahdi\dataParsers\data\embed_listwise\majles_mj_qa_context_context.json"), data=documents
|
|
)
|
|
|
|
# cd dataParsers
|
|
# python -m app.save_content_id
|