Repository: explodinggradients/ragas
Issue: Ragas with Llama-Index not working correctly due to misdefined scope
Root cause: Validation Gap

[x] I have checked the [documentation](https://docs.ragas.io/) and related resources and couldn't resolve my bug.

**Describe the bug**
When trying to generate a test set using generate_with_llamaindex_docs, the code fails with a NameError indicating that 'LCDocument' is not defined. This appears to be an internal import issue in the Ragas library where the Langchain Document class is not properly imported in the scope where it's being used.

Ragas version: 0.2.6
Python version: 3.10.11

**Code to Reproduce**
```
from llama_index.core import SimpleDirectoryReader
from ragas.testset import TestsetGenerator
from llama_index.llms.openai import OpenAI
from llama_index.embeddings.openai import OpenAIEmbedding

# Load documents
documents = SimpleDirectoryReader("./nyc_wikipedia").load_data()

# Initialize generator components
generator_llm = OpenAI(model="gpt-4")
embeddings = OpenAIEmbedding(model="text-embedding-3-large")

# Create generator
generator = TestsetGenerator.from_llama_index(
    llm=generator_llm,
    embedding_model=embeddings,
)

# Generate testset
testset = generator.generate_with_llamaindex_docs(
    documents,
    testset_size=5,
)

```

**Error trace**
```
NameError                                 Traceback (most recent call last)
Cell In[4], line 2
      1 # generate testset
----> 2 testset = generator.generate_with_llamaindex_docs(
      3     documents,
      4     testset_size=5,
      5 )

File [...]/ragas/testset/synthesizers/generate.py:241, in TestsetGenerator.generate_with_llamaindex_docs(self, documents, testset_size, transforms, transforms_llm, transforms_embedding_model, query_distribution, run_config, callbacks, with_debugging_logs, raise_exceptions)
    240     transforms = default_transforms(
--> 241         documents=[LCDocument(page_content=doc.text) for doc in documents],
    242         llm=llm_for_transforms,
    243         embedding_model=embedding_model_for_transforms,
    244     )

NameError: name 'LCDocument' is not defined
```


**Expected behavior**
I expected it to generate a test set like described in the guide.


Yes, I'm also facing the same issue with LlamaIndex.

I am also facing the same issue. Any update on this and what could be causing it? Could it be an environment dependency? 


Okay so I see the culprit is the type checking done at the beginning of this script. I'm not sure on how to fix this as typing is a notorious issue in python. 

Also, I see a typo in the generate_with_llamaindex_docs function where it uses the LCDocument instead of the LlamaIndexDocument. I believe this is a typo anyway but not sure until confirmation. Happy to submit the correction if I'm correct. 

https://github.com/explodinggradients/ragas/blob/main/src/ragas/testset/synthesizers/generate.py 


delete this type is ok, this relies on langchain , not llama_index

I also get this kind of error in 0.2.8.

```python
from datasets import load_dataset

data = ds.to_pandas()

from llama_index.core import Document, VectorStoreIndex
docs = []

for i, row in data.iterrows():
    docs.append(Document(
        text=row['text'],
        # extra_info={'title': row['title']}
    ))

from ragas.testset import TestsetGenerator

from llama_index.llms.openai import OpenAI
from llama_index.embeddings.openai import OpenAIEmbedding

# generator with openai models
generator_llm = OpenAI(model="gpt-4o-mini")
embeddings = OpenAIEmbedding(model="text-embedding-3-large")

generator = TestsetGenerator.from_llama_index(
    llm=generator_llm,
    embedding_model=embeddings,
)

# generate testset
testset = generator.generate_with_llamaindex_docs(
    docs,
    testset_size=5,
)
```

```python
NameError                                 Traceback (most recent call last)
Cell In[10], line 2
      1 # generate testset
----> 2 testset = generator.generate_with_llamaindex_docs(
      3     docs,
      4     testset_size=5,
      5 )

File python3.11/site-packages/ragas/testset/synthesizers/generate.py:241, in TestsetGenerator.generate_with_llamaindex_docs(self, documents, testset_size, transforms, transforms_llm, transforms_embedding_model, query_distribution, run_config, callbacks, with_debugging_logs, raise_exceptions)
    235         embedding_model_for_transforms = LlamaIndexEmbeddingsWrapper(
    236             transforms_embedding_model
    237         )
    239     # create the transforms
    240     transforms = default_transforms(
--> 241         documents=[LCDocument(page_content=doc.text) for doc in documents],
    242         llm=llm_for_transforms,
    243         embedding_model=embedding_model_for_transforms,
    244     )
    246 # convert the documents to Ragas nodes
    247 nodes = []

File python3.11/site-packages/ragas/testset/synthesizers/generate.py:241, in <listcomp>(.0)
    235         embedding_model_for_transforms = LlamaIndexEmbeddingsWrapper(
    236             transforms_embedding_model
    237         )
    239     # create the transforms
    240     transforms = default_transforms(
--> 241         documents=[LCDocument(page_content=doc.text) for doc in documents],
    242         llm=llm_for_transforms,
    243         embedding_model=embedding_model_for_transforms,
    244     )
    246 # convert the documents to Ragas nodes
    247 nodes = []

NameError: name 'LCDocument' is not defined
```


I am facing the same issue, when tried to follow the [LlamaIndex](https://docs.ragas.io/en/stable/howtos/integrations/_llamaindex/) building testset. I am on ragas `0.2.9`. 

I was able to fix it by moving `from langchain_core.documents import Document as LCDocument` in generate.py source file out of the if condition of TYPE_CHECKING
![Screenshot 2024-12-30 at 11 19 46 PM](https://github.com/user-attachments/assets/faea36c0-c2a7-4488-af8e-efe26043c380)


hey folks, I've pushed a fix for this and will merge it shortly and will be out in next weeks release

apologizes for the delay in this fix 🙏🏽