Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from elasticsearch import Elasticsearch
- from elasticsearch.helpers import bulk
- es = Elasticsearch()
- def index_documents(documents):
- actions = [
- {
- "_index": "hybrid_search",
- "_id": doc["id"],
- "_source": {
- "content": doc["content"],
- "vector": doc["embedding"]
- }
- }
- for doc in documents
- ]
- bulk(es, actions)
- # Usage
- docs = [
- {"id": 1, "content": "Java performance tuning", "embedding": [0.1, 0.2, ...]},
- {"id": 2, "content": "Optimizing database queries", "embedding": [0.3, 0.4, ...]}
- ]
- index_documents(docs)
Advertisement
Add Comment
Please, Sign In to add comment