topoteretes / cognee

Reliable LLM Memory for AI Applications and AI Agents
https://www.cognee.ai
Apache License 2.0
822 stars 57 forks source link

KeyError: 'name' #108

Closed Material-Scientist closed 3 months ago

Material-Scientist commented 3 months ago

Hi,

I can't seem to get your example working:

import cognee

cognee.config.llm_api_key = "OpenAI_API_KEY"

text = """Natural language processing (NLP) is an interdisciplinary
       subfield of computer science and information retrieval"""

await cognee.add([text], "example_dataset") # Add a new piece of information

await cognee.cognify() # Use LLMs and cognee to create knowledge

search_results = await cognee.search("SIMILARITY", "computer science") # Query cognee for the knowledge

for result_text in search_results[0]:
    print(result_text)

Error:

KeyError                                  Traceback (most recent call last)
Cell In[1], line 8
      3 cognee.config.llm_api_key = "OpenAI_API_KEY"
      5 text = """Natural language processing (NLP) is an interdisciplinary
      6        subfield of computer science and information retrieval"""
----> 8 await cognee.add([text], "example_dataset") # Add a new piece of information
     10 await cognee.cognify() # Use LLMs and cognee to create knowledge
     12 search_results = await cognee.search("SIMILARITY", "computer science") # Query cognee for the knowledge

File [~/miniconda3/envs/AI/lib/python3.10/site-packages/cognee/api/v1/add/add.py:44](http://localhost:8889/lab/tree/AI-Playground/miniconda3/envs/AI/lib/python3.10/site-packages/cognee/api/v1/add/add.py#line=43), in add(data, dataset_name)
     42         file_paths.append(data_item)
     43     elif isinstance(data_item, str):
---> 44         file_paths.append(save_data_to_file(data_item, dataset_name))
     46 if len(file_paths) > 0:
     47     return await add_files(file_paths, dataset_name)

File [~/miniconda3/envs/AI/lib/python3.10/site-packages/cognee/modules/ingestion/save_data_to_file.py:16](http://localhost:8889/lab/tree/AI-Playground/miniconda3/envs/AI/lib/python3.10/site-packages/cognee/modules/ingestion/save_data_to_file.py#line=15), in save_data_to_file(data, dataset_name, filename)
     13 LocalStorage.ensure_directory_exists(storage_path)
     15 file_metadata = classified_data.get_metadata()
---> 16 file_name = file_metadata["name"]
     17 LocalStorage(storage_path).store(file_name, classified_data.get_data())
     19 return "fil[e://](file:///E://)" + storage_path + "/" + file_name

It seems the library assumes that the key "name" is present in the file_metadata, and raises an error due to its absence.

OS: Ubuntu 20.04.5 Python: 3.10.11 Cognee: 0.1.11

This was attempted on a fresh conda environment inside a JupyterLab notebook.

Vasilije1990 commented 3 months ago

Hi, thanks. We are working on it, with the https://github.com/topoteretes/cognee/pull/106 expected to be merged and a release made tonight. The example in the collab notebook should work: https://colab.research.google.com/drive/1jayZ5JRwDaUGFvCw9UZySBG-iB9gpYfu?usp=sharing Also, when adding files instead of strings, we didn't observe this issue.

Thanks for raising it.

Vasilije1990 commented 3 months ago

@Material-Scientist the issue is resolved now with the new release, 2 minutes to midnight. If you face other issues, please let us know. We've updated the documentation too