i get this error
Traceback (most recent call last):
File “/Users/eleana/Documents/Uncharted_Limbo/Github/HF_Spaces/ioniq-tree-article/rag_index_creator.py”, line 112, in
create_index(weather_path, weather_faiss, weather_meta)
File “/Users/eleana/Documents/Uncharted_Limbo/Github/HF_Spaces/ioniq-tree-article/rag_index_creator.py”, line 71, in create_index
index = faiss.IndexFlatL2(embeddings.shape[1])
IndexError: tuple index out of range
trying to embed this json
[
{
“id”: 9,
“name”: “The Winter Breeze of the Travnŷ Hiils”,
“content”: [
“The wind in the Beskydy is so unpredictable this time of the year. Sometimes days pass without any wind, apart from the occasional gust. Then suddenly there are days of constant breeze, nothing serious or dangerous. One thing is certain, that the breezes are stronger during the day, when temperatures are higher. And a strange thing occurs in this area of Beskydy: Usually breezes come from the valley southwest, from where the river is. But during some nights, the winds turn and come from north east, from the slopes above.”
],
“story_metadata”: {
“title”: “The Winter Breeze of the Travnŷ Hiils”,
“event_type”: “Enduring”,
“location”: “Travný (Czechia)”,
“temporal”: “This Winter”
},
“sensor_metadata”: [
{
“id”: 20,
“title”: “Wind Observations”,
“event_type”: “Enduring”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-04T00:00:00”,
“daterange_to”: “2025-02-25T00:00:00”,
“variable”: [
“Wind Speed (m/s)”,
“Wind Direction”
],
“datasource”: “ATMOS 41 - Weather Station”,
“description”: “Wind Speeds stayed low during February, exceeding 1.5 m/s, only once, staying on average around 0.75m/s. Wind Gusts peaked at 4m/s, on average being around 2m/s. This is considered “Light Air”, or “Light Breeze” at most. A pattern of slightly higher wind speeds during warm days, and almost 0 m/s during the night can be observed.”
},
{
“id”: 7,
“title”: “Solar Radiation Observations”,
“event_type”: “Periodic”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-04T00:00:00”,
“daterange_to”: “2025-02-25T00:00:00”,
“variable”: [
“PPFD (µmol·m⁻²·s⁻¹)”
],
“datasource”: “Apogee SQ-521 - PAR Sensor”,
“description”: “At around 7:00am every day the first photons reach the site The amount of solar energy increases at a low rate the first 2 hours (from 0 to 40 micromols), but there is a very sudden increase at around 9:30 (from 40 to 350 micromols). At 12:30pm there is a peak in Solar Radiation for most days, with consistent in radiation levels of roughly 700 micromols, indicating complete absence of cloud cover. Every day there are two shading events with radiation suddenly droping to roughly 200 micromols, likely due to neighbouring trees.”
},
{
“id”: 21,
“title”: “Cloudy Day 1”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-14T00:00:00”,
“daterange_to”: "",
“variable”: [
“PPFD (µmol·m⁻²·s⁻¹)”
],
“datasource”: “Apogee SQ-521 - PAR Sensor”,
“description”: “A cloudy day, predicted by a sudden pressure drop the day before, with PPFD values barely reaching 20 micromols.”
},
{
“id”: 22,
“title”: “Cloudy Days 2”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-06T00:00:00”,
“daterange_to”: “2025-02-07T00:00:00”,
“variable”: [
“PPFD (µmol·m⁻²·s⁻¹)”
],
“datasource”: “Apogee SQ-521 - PAR Sensor”,
“description”: “Two consecutive cloudy days, predicted by a small pressure drop the day before, with PPFD values barely reaching 50 micromols.”
}
]
},
{
“id”: 8,
“name”: “The Cold Spell of February”,
“content”: [
“After a few days of relatively warm weather in the beginning of February, the temperature started dropping below 0 during the daytime. Slowly at first, then rapidly until it reached -10 and it stayed like that for a few days. The sun kept shining bright, but it was not enough to lift the temperature above the freezing point. During this time, the soil started cooling down slowly. It never froze, even after days of very cold air. At the same time, the soil kept drying. This combination of dry and cold soil can be stressful if it lasts too long, as it can lead to drought stress, an inability of the roots to absorb water and nutrients from the ground.”,
“However, after a few days of consistently low temperatures, the cold spell came to an end. Every day started becoming warmer than the previous. The sun kept shining bright, warming the air during the daytime, despite the sharp night temperature drops. After 4 days of continuous warmth, the day temperature finally climbed above the freezing point of water, and kept rising, never going above 5 degrees celsius.”
],
“story_metadata”: {
“title”: “The Cold Spell of February”,
“event_type”: “Enduring”,
“location”: “Travný (Czechia)”,
“temporal”: “A Week Towards the End of The Winter”
},
“sensor_metadata”: [
{
“id”: 16,
“title”: “Air Temperature Drop”,
“event_type”: “Enduring”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-11T00:00:00”,
“daterange_to”: “2025-02-19T00:00:00”,
“variable”: [
“Air Temperature (°C)”
],
“datasource”: “ATMOS 41 - Weather Station”,
“description”: “The daytime temperature started dropping below 0 degrees C. Slow temperature drops during the first 2 days, then rapid fall the next 3 days until it reached -10 degrees Celsius. Steady minimum -10 and maximum -6 temperatures for the next 3 days”
},
{
“id”: 17,
“title”: “Air Temperature Rise”,
“event_type”: “Enduring”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-19T00:00:00”,
“daterange_to”: “2025-02-24T00:00:00”,
“variable”: [
“Air Temperature (°C)”
],
“datasource”: “ATMOS 41 - Weather Station”,
“description”: “Steady temperature increase with diurnal fluctuations. Within 4 days the maximum daily temperature increased from -6 to 6 degrees Celsius, while the minimum daily temperature increased from -10 to 2.7 degrees”
},
{
“id”: 18,
“title”: “Soil Temperature Drop”,
“event_type”: “Enduring”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-11T00:00:00”,
“daterange_to”: “2025-02-24T00:00:00”,
“variable”: [
“Soil Temperature (°C)”
],
“datasource”: “TEROS 21 - Soil Sensor”,
“description”: “Steady and slow temperature decline, between 2 precipitation events. The temperature dropped from 3 degrees to 0.5 within 2 weeks.”
},
{
“id”: 7,
“title”: “Solar Radiation Observations”,
“event_type”: “Periodic”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-04T00:00:00”,
“daterange_to”: “2025-02-25T00:00:00”,
“variable”: [
“PPFD (µmol·m⁻²·s⁻¹)”
],
“datasource”: “Apogee SQ-521 - PAR Sensor”,
“description”: “At around 7:00am every day the first photons reach the site The amount of solar energy increases at a low rate the first 2 hours (from 0 to 40 micromols), but there is a very sudden increase at around 9:30 (from 40 to 350 micromols). At 12:30pm there is a peak in Solar Radiation for most days, with consistent in radiation levels of roughly 700 micromols, indicating complete absence of cloud cover. Every day there are two shading events with radiation suddenly droping to roughly 200 micromols, likely due to neighbouring trees.”
},
{
“id”: 12,
“title”: “Slow Depletion of Soil Moisture”,
“event_type”: “Enduring”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-10T00:00:00”,
“daterange_to”: “2025-02-23T00:00:00”,
“variable”: [
“Water Content (m³/m³)”
],
“datasource”: “TEROS 12 - Soil Sensor”,
“description”: “Steady and slow water content decline, between 2 precipitation events. The water content dropped from 0.41 m3 to 0.38 m3 within 2 weeks.”
},
{
“id”: 21,
“title”: “Cloudy Day 1”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-14T00:00:00”,
“daterange_to”: "",
“variable”: [
“PPFD (µmol·m⁻²·s⁻¹)”
],
“datasource”: “Apogee SQ-521 - PAR Sensor”,
“description”: “A cloudy day, predicted by a sudden pressure drop the day before, with PPFD values barely reaching 20 micromols.”
},
{
“id”: 22,
“title”: “Cloudy Days 2”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-06T00:00:00”,
“daterange_to”: “2025-02-07T00:00:00”,
“variable”: [
“PPFD (µmol·m⁻²·s⁻¹)”
],
“datasource”: “Apogee SQ-521 - PAR Sensor”,
“description”: “Two consecutive cloudy days, predicted by a small pressure drop the day before, with PPFD values barely reaching 50 micromols.”
}
]
},
{
“id”: 6,
“name”: “The Heavy Rainfall at the End of Winter”,
“content”: [
“The first big rain after 2 weeks. The needles of the Silver Firs got really wet, the wettest they’ve been this winter. Alarmingly, the soil was drying for 2 weeks, which in combination with the cold temperatures could lead to drought stress. But thankfully, due to the heavy rain, soil water reached a peak in a single day. It took almost a day for the water to reach the deeper roots. The soil got just a little bit warmer, likely due to the rain. The air felt moist and full, the water vapour deficit was very low. With all this moisture around, the air wasn’t thirsty.”
],
“story_metadata”: {
“title”: “The Heavy Rainfall at the End of Winter”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“temporal”: “A Day Towards the End of The Winter”
},
“sensor_metadata”: [
{
“id”: 13,
“title”: “Precipitation Event”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-24T00:00:00”,
“daterange_to”: "",
“variable”: [
“Precipitation (mm)”
],
“datasource”: “ATMOS 41 - Weather Station”,
“description”: “Sharp spike in precipitation. Sustained precipitation (peak 0.3mm) for 10 hours”
},
{
“id”: 14,
“title”: “Soil Moisture Peak”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-24T00:00:00”,
“daterange_to”: "",
“variable”: [
“Water Content (m³/m³)”
],
“datasource”: “TEROS 12 - Soil Sensor”,
“description”: “Sharp spike in Soil Water Content, directly linked to the Precipitation event. Phase delay of about 12 hours for the soil to reach peak saturation of 0.41m3 / m3. Sustained water content value for the next 24 hours”
},
{
“id”: 15,
“title”: “Leaf Wetness Peak”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-24T00:00:00”,
“daterange_to”: "",
“variable”: [
“Leaf Wetness Level (counts)”
],
“datasource”: “PHYTOS 31 - Leaf Wetness”,
“description”: “Sharp spike in Leaf Wetness, directly linked to the Precipitation event. By far the highest value of February (515 counts) indicating the first serious precipitation event of the month”
},
{
“id”: 12,
“title”: “Slow Depletion of Soil Moisture”,
“event_type”: “Enduring”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-10T00:00:00”,
“daterange_to”: “2025-02-23T00:00:00”,
“variable”: [
“Water Content (m³/m³)”
],
“datasource”: “TEROS 12 - Soil Sensor”,
“description”: “Steady and slow water content decline, between 2 precipitation events. The water content dropped from 0.41 m3 to 0.38 m3 within 2 weeks.”
}
]
},
{
“id”: 2,
“name”: “The Daily Routine of Solar Energy”,
“content”: [
“Every morning this winter, the first solar rays appear over the Southeastern hill. Every day, for 2 hours more or less, the sun, still being low, shines through the tall and thick trunks of the Beech trees, barely making it through. Every day, no later than 9:30, the sun finally breaks over the branches and appears full. This is a very sudden, very welcome dose of energy that marks the beginning of a warm winter day. Every day, two Beech tree trees cast their shade on the Silver fir. One at 11:30, the other at 13:00. Same time every day. All the trees on this hill, apart from the Silver Firs have lost their leaves. This allows the Firs to receive the maximum solar energy that the sun has to offer. This has been an exceptionally sunny winter, since almost every day the skies were clear, apart from 3 days, when clouds covered the sky. This was inevitable, as the air become lighter, inviting the clouds to form. Overall during the last month of Winter, the photosynthetic activity of the Firs in the area had enough solar energy. However, the warm sun facilitates the evaporation of soil water. The soil becomes drier with every passing day. 2 weeks without rain were enough for the soil moisture to reach its minimum value for the month.”
],
“story_metadata”: {
“title”: “The Daily Routine of Solar Energy”,
“event_type”: “Periodic”,
“location”: “Travný (Czechia)”,
“temporal”: “This Winter”
},
“sensor_metadata”: [
{
“id”: 7,
“title”: “Solar Radiation Observations”,
“event_type”: “Periodic”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-04T00:00:00”,
“daterange_to”: “2025-02-25T00:00:00”,
“variable”: [
“PPFD (µmol·m⁻²·s⁻¹)”
],
“datasource”: “Apogee SQ-521 - PAR Sensor”,
“description”: “At around 7:00am every day the first photons reach the site The amount of solar energy increases at a low rate the first 2 hours (from 0 to 40 micromols), but there is a very sudden increase at around 9:30 (from 40 to 350 micromols). At 12:30pm there is a peak in Solar Radiation for most days, with consistent in radiation levels of roughly 700 micromols, indicating complete absence of cloud cover. Every day there are two shading events with radiation suddenly droping to roughly 200 micromols, likely due to neighbouring trees.”
},
{
“id”: 8,
“title”: “Atmospheric Pressure Drop_1”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-07T00:00:00”,
“daterange_to”: “2025-02-08T00:00:00”,
“variable”: [
“Atmospheric Pressure (kPa)”
],
“datasource”: “ATMOS 41 - Weather Station”,
“description”: “Pressure Drop from 94 kPa to 93.5kPA”
},
{
“id”: 9,
“title”: “Atmospheric Pressure Drop_2”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-08T00:00:00”,
“daterange_to”: “2025-02-13T00:00:00”,
“variable”: [
“Atmospheric Pressure (kPa)”
],
“datasource”: “ATMOS 41 - Weather Station”,
“description”: “Pressure Drop from 93.5 kPa to 92.1kPA”
},
{
“id”: 12,
“title”: “Slow Depletion of Soil Moisture”,
“event_type”: “Enduring”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-10T00:00:00”,
“daterange_to”: “2025-02-23T00:00:00”,
“variable”: [
“Water Content (m³/m³)”
],
“datasource”: “TEROS 12 - Soil Sensor”,
“description”: “Steady and slow water content decline, between 2 precipitation events. The water content dropped from 0.41 m3 to 0.38 m3 within 2 weeks.”
},
{
“id”: 21,
“title”: “Cloudy Day 1”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-14T00:00:00”,
“daterange_to”: "",
“variable”: [
“PPFD (µmol·m⁻²·s⁻¹)”
],
“datasource”: “Apogee SQ-521 - PAR Sensor”,
“description”: “A cloudy day, predicted by a sudden pressure drop the day before, with PPFD values barely reaching 20 micromols.”
},
{
“id”: 22,
“title”: “Cloudy Days 2”,
“event_type”: “Sudden Event”,
“location”: “Travný (Czechia)”,
“daterange_from”: “2025-02-06T00:00:00”,
“daterange_to”: “2025-02-07T00:00:00”,
“variable”: [
“PPFD (µmol·m⁻²·s⁻¹)”
],
“datasource”: “Apogee SQ-521 - PAR Sensor”,
“description”: “Two consecutive cloudy days, predicted by a small pressure drop the day before, with PPFD values barely reaching 50 micromols.”
}
]
}
]
like this
def create_index(json_path, faiss_index_path, metadata_path):
# Load embedding model
embedding_model = SentenceTransformer(‘all-MiniLM-L6-v2’)
with open(json_path, 'r', encoding='utf-8') as f:
content = item.get("content", [])
if isinstance(content, list):
for section_dict in content:
if isinstance(section_dict, dict):
for section, text_list in section_dict.items():
full_text = f"{section}:\n" + "\n".join([text.strip() for text in text_list if text.strip()])
print(f"PROCESSING ITEM --- {full_text}")
#metadata.append(item.get("source", {})) # Store only the source metadata
"source": item.get("source", {}), # Store only the source metadata
"original_text": full_text # Store original text for retrieval
elif isinstance(section_dict, list):
for section in section_dict:
full_text = "\n".join([text.strip() for text in section if text.strip()])
print(f"PROCESSING ITEM --- {full_text}")
#metadata.append(item.get("source", {})) # Store only the source metadata
"source": item.get("source", {}), # Store only the source metadata
"original_text": full_text # Store original text for retrieval