Skip to content

Commit

Permalink
Replace Chroma DocumentStore with InMemory (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
bilgeyucel authored Jul 17, 2024
1 parent 6f9c66b commit e423aa8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions content/overview/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ Try out how Haystack answers questions about the given documents using the **RAG
{{< tabs totalTabs="3">}}

{{< tab tabName="Quickstart: Ready-Made Template" >}}
First, install Haystack and the [Chroma integration](https://haystack.deepset.ai/integrations/chroma-documentstore) (we will use it as our document store):
Install Haystack:

```bash
pip install haystack-ai chroma-haystack
pip install haystack-ai
```

```python
Expand All @@ -146,29 +147,29 @@ print(result["llm"]["replies"][0])
{{< /tab >}}

{{< tab tabName="Corresponding Pipeline" >}}
First, install Haystack and the [Chroma integration](https://haystack.deepset.ai/integrations/chroma-documentstore) (we will use it as our document store):
Install Haystack:

```bash
pip install haystack-ai chroma-haystack
pip install haystack-ai
```
```python
import os
import urllib.request

from haystack import Pipeline
from haystack_integrations.document_stores.chroma import ChromaDocumentStore
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.retrievers import InMemoryEmbeddingRetriever
from haystack.components.converters import TextFileToDocument
from haystack.components.preprocessors import DocumentCleaner, DocumentSplitter
from haystack.components.embedders import OpenAIDocumentEmbedder, OpenAITextEmbedder
from haystack.components.writers import DocumentWriter

from haystack_integrations.components.retrievers.chroma import ChromaEmbeddingRetriever
from haystack.components.builders import PromptBuilder
from haystack.components.generators import OpenAIGenerator
import urllib.request

os.environ["OPENAI_API_KEY"] = "Your OpenAI API Key"
urllib.request.urlretrieve("https://www.gutenberg.org/cache/epub/7785/pg7785.txt", "davinci.txt")

document_store = ChromaDocumentStore(persist_path=".")
document_store = InMemoryDocumentStore()

text_file_converter = TextFileToDocument()
cleaner = DocumentCleaner()
Expand All @@ -190,7 +191,7 @@ indexing_pipeline.connect("embedder.documents", "writer.documents")
indexing_pipeline.run(data={"sources": ["davinci.txt"]})

text_embedder = OpenAITextEmbedder()
retriever = ChromaEmbeddingRetriever(document_store)
retriever = InMemoryEmbeddingRetriever(document_store)
template = """Given these documents, answer the question.
Documents:
{% for doc in documents %}
Expand All @@ -211,7 +212,7 @@ rag_pipeline.connect("text_embedder.embedding", "retriever.query_embedding")
rag_pipeline.connect("retriever.documents", "prompt_builder.documents")
rag_pipeline.connect("prompt_builder", "llm")

query = "How old was he when he died?"
query = "How old was Leonardo when he died?"
result = rag_pipeline.run(data={"prompt_builder": {"query":query}, "text_embedder": {"text": query}})
print(result["llm"]["replies"][0])
```
Expand Down
Binary file modified static/images/rag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e423aa8

Please sign in to comment.