Repository: explodinggradients/ragas
Issue: AttributeError: 'str' object has no attribute 'docstore'
Root cause: Validation Gap

[ ] I have checked the [documentation](https://docs.ragas.io/) and related resources and couldn't resolve my bug.

**Describe the bug**
AttributeError: 'str' object has no attribute 'docstore'

Ragas version:3.10.12
Python version:0.1.10

**Code to Reproduce**
from langchain_community.document_loaders import PubMedLoader
nest_asyncio.apply()
loader = PubMedLoader("liver", load_max_docs=10)
documents = loader.load()
print(len(documents))
generator = TestsetGenerator.from_langchain(
    generator_llm=llm,
    critic_llm=llm,
    embeddings=embeddings,
)

testset = generator.generate_with_langchain_docs(documents, test_size=2, distributions={'simple': 0.5, 'reasoning': 0.25, 'multi_context': 0.25},is_async = False,raise_exceptions=False)

**Error trace**
[<ipython-input-12-b680351d3605>](https://localhost:8080/#) in <cell line: 12>()
     10 )
     11 
---> 12 testset = generator.generate_with_langchain_docs(documents, test_size=2, distributions={'simple': 0.5, 'reasoning': 0.25, 'multi_context': 0.25},is_async = False,raise_exceptions=False)

2 frames
[/usr/local/lib/python3.10/dist-packages/ragas/testset/generator.py](https://localhost:8080/#) in generate_with_langchain_docs(self, documents, test_size, distributions, with_debugging_logs, is_async, raise_exceptions, run_config)
    208         )
    209 
--> 210         return self.generate(
    211             test_size=test_size,
    212             distributions=distributions,

[/usr/local/lib/python3.10/dist-packages/ragas/testset/generator.py](https://localhost:8080/#) in generate(self, test_size, distributions, with_debugging_logs, is_async, raise_exceptions, run_config)
    256         # init filters and evolutions
    257         for evolution in distributions:
--> 258             self.init_evolution(evolution)
    259             evolution.init(is_async=is_async, run_config=run_config)
    260 

[/usr/local/lib/python3.10/dist-packages/ragas/testset/generator.py](https://localhost:8080/#) in init_evolution(self, evolution)
    218 
    219     def init_evolution(self, evolution: Evolution) -> None:
--> 220         evolution.docstore = self.docstore
    221 
    222         if evolution.generator_llm is None:

AttributeError: 'str' object has no attribute 'docstore'

**Expected behavior**
A clear and concise description of what you expected to happen.


**Additional context**
Add any other context about the problem here.

<!-- PS: bugs suck but is also part of the process. We sincerely apologies for breaking your flow because of it, but don't worry, we got your back ❤️. We will get this fixed as fast as we can and thanks for helping us out by reporting it 🙏. -->


<!-- Answer -->
To resolve the `AttributeError: 'str' object has no attribute 'docstore'`, ensure that you are passing an instance of `DocumentStore` (or its subclass) to the `docstore` parameter, not a string. Here's how you can correctly instantiate the `TestsetGenerator`:

```python
from ragas.testset.generator import TestsetGenerator
from ragas.testset.docstore import InMemoryDocumentStore
from langchain_openai.chat_models import ChatOpenAI
from langchain_openai.embeddings import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter

# Initialize the necessary components
generator_llm = ChatOpenAI(model="gpt-3.5-turbo-16k")
critic_llm = ChatOpenAI(model="gpt-4")
embeddings = OpenAIEmbeddings(model="text-embedding-ada-002")
splitter = CharacterTextSplitter(chunk_size=1000)
docstore = InMemoryDocumentStore(splitter=splitter)

# Create the TestsetGenerator instance
generator = TestsetGenerator(
    generator_llm=generator_llm,
    critic_llm=critic_llm,
    embeddings=embeddings,
    docstore=docstore
)

# Generate the test set
testset = generator.generate_with_langchain_docs(
    documents, 
    test_size=2, 
    distributions={'simple': 0.5, 'reasoning': 0.25, 'multi_context': 0.25}, 
    is_async=False, 
    raise_exceptions=False
)
```

Make sure that `docstore` is an instance of `DocumentStore` or `InMemoryDocumentStore`, not a string. Additionally, ensure that the `splitter` parameter is correctly initialized and passed to the `InMemoryDocumentStore` <sup>[[1]](https://github.com/explodinggradients/ragas/blob/main/src/ragas/testset/generator.py)</sup><sup>[[2]](https://github.com/explodinggradients/ragas/blob/main/src/ragas/testset/docstore.py)</sup>.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*