Skip to content

Commit

Permalink
Update documentation for Haystack integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Yugsolanki committed Nov 9, 2024
1 parent d604342 commit e54d0d5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions docs/docs.trychroma.com/pages/integrations/haystack.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ from pathlib import Path
from haystack import Pipeline
from haystack.components.converters import TextFileToDocument
from haystack.components.writers import DocumentWriter
from chroma_haystack import ChromaDocumentStore
from haystack_integrations.document_stores.chroma import ChromaDocumentStore

file_paths = ["data" / Path(name) for name in os.listdir("data")]

Expand All @@ -47,9 +47,10 @@ indexing.run({"converter": {"sources": file_paths}})
#### Build RAG on top of Chroma

```python
from chroma_haystack.retriever import ChromaQueryRetriever
from haystack.components.generators import HuggingFaceTGIGenerator
from haystack_integrations.components.retrievers.chroma import ChromaQueryTextRetriever
from haystack.components.generators import HuggingFaceAPIGenerator
from haystack.components.builders import PromptBuilder
from haystack.utils import Secret

prompt = """
Answer the query based on the provided context.
Expand All @@ -63,9 +64,10 @@ Answer:
"""
prompt_builder = PromptBuilder(template=prompt)

llm = HuggingFaceTGIGenerator(model="mistralai/Mixtral-8x7B-Instruct-v0.1", token='YOUR_HF_TOKEN')
llm.warm_up()
retriever = ChromaQueryRetriever(document_store)
llm = HuggingFaceAPIGenerator(api_type="serverless_inference_api",
api_params={"model": "mistralai/Mixtral-8x7B-Instruct-v0.1"},
token=Secret.from_token("YOUR_HF_TOKEN"))
retriever = ChromaQueryTextRetriever(document_store)

querying = Pipeline()
querying.add_component("retriever", retriever)
Expand All @@ -75,6 +77,10 @@ querying.add_component("llm", llm)
querying.connect("retriever.documents", "prompt_builder.documents")
querying.connect("prompt_builder", "llm")

results = querying.run({"retriever": {"queries": [query], "top_k": 3},
query = "What is the capital of France?" # query to search for in the documents

results = querying.run({"retriever": {"query": query, "top_k": 3},
"prompt_builder": {"query": query}})

print(results)
```

0 comments on commit e54d0d5

Please sign in to comment.