openai elasticsearch rag
1.0.0
RAG (Generation-uugmented Retrieval-Augmented) เพื่อเสนอคำถามและคำตอบบนข้อความรูปแบบยาวโดยใช้ OpenAI และ Elasticsearch ที่นี่เราอยู่
python -m venv venv source venv/bin/activatepip install -r requirements.txtpython -m spacy download en_core_web_smbin/elasticsearch (หรือ binelasticsearch.bat บน Windows)curl -X GET "localhost:9200/" ในเทอร์มินัล ก่อนที่จะเรียกใช้แอพให้สร้างไฟล์ .env โดยใช้ .env-template และเพิ่มคีย์ OpenAI API และข้อมูลรับรอง Elasticsearch
python run.py แอพจะเริ่มต้นที่ localhost บนพอร์ต 8081 ตรวจสอบสติโดยทำงานในเทอร์มินัล ควรส่งคืนข้อความ Hello
curl -X GET " localhost:8081 " curl --location --request PUT ' http://localhost:9200/first-index '
--header ' Content-Type: application/json '
--data-raw ' {
"mappings": {
"properties": {
"text": {
"type": "text"
},
"embedding": {
"type": "dense_vector",
"dims": 1536
}
}
}
} 'หากคุณต้องการลบดัชนีสำหรับการเริ่มต้นที่สะอาดให้ใช้คำสั่งต่อไปนี้
curl --location --request DELETE ' http://localhost:9200/first-index ' ในการจัดทำดัชนีข้อมูลให้ใช้คำสั่ง curl ต่อไปนี้ คำสั่งนี้จะส่งคำขอโพสต์ไปยังจุดสิ้นสุดที่ระบุด้วยเพย์โหลด JSON ที่มีข้อความที่จะจัดทำดัชนีและชื่อของดัชนี
ตรวจสอบให้แน่ใจว่าคุณให้เซิร์ฟเวอร์ทำงานบน localhost บนพอร์ต 8081
curl --location --request POST ' localhost:8081/api/index '
--header ' Content-Type: application/json '
--data-raw ' {
"text": "Ajeet is an engineer turned product entrepreneur with experience in AI, SaaS, HealthTech and EdTech. He is a technology enthusiast and loves to work on new technologies. He was a founding member of leading health-tech startups HealthKart and TATA 1mg in India. He was the founder of Joe Hukum, a chatbot platform which was acquired by Freshworks. After Freshworks, he founded Seekho.ai to solve for the skill gap in Indian higher education. Currently, he is on a break and is exploring GenAI to solve for the next meaningful problem. He is passionate about solving zero to one problems and building products that can impact millions of lives.",
"index_name": "first-index"
} 'ตัวอย่างที่ 1:
curl --location --request POST ' localhost:8081/api/query '
--header ' Content-Type: application/json '
--data-raw ' {
"question": "Who is Ajeet?",
"index_name": "first-index"
} 'ตัวอย่างที่ 2:
curl --location --request POST ' localhost:8081/api/query '
--header ' Content-Type: application/json '
--data-raw ' {
"question": "Joe Hukum was acquired by which company?",
"index_name": "first-index"
} '