Skip to main content

Needle RAG tools for Haystack

Project description

Needle RAG tools for Haystack

PyPI - Version PyPI - Python Version

This package provides NeedleDocumentStore and NeedleEmbeddingRetriever component for use in Haystack projects.

Usage ⚡️

Get started by installing the package via pip.

pip install needle-haystack

API Keys

We will show you building a common RAG pipeline using Needle tools and OpenAI generator. For using these tools you must set your environment variables, NEEDLE_API_KEY and OPENAI_API_KEY respectively.

You can get your Needle API key from from Developer settings.

Example Pipeline 🧱

In Needle document stores are called collections. For detailed information, see our docs. You can create a reference to your Needle collection using NeedleDocumentStore and use NeedleEmbeddingRetriever to retrieve documents from it.

from needle_haystack import NeedleDocumentStore, NeedleEmbeddingRetriever

document_store = NeedleDocumentStore(collection_id="<your-collection-id>")
retriever = NeedleEmbeddingRetriever(document_store=document_store)

Use the retriever in a Haystack pipeline. Example:

from haystack import Pipeline
from haystack.components.generators import OpenAIGenerator
from haystack.components.builders import PromptBuilder

prompt_template = """
Given the following retrieved documents, generate a concise and informative answer to the query:

Query: {{query}}
Documents:
{% for doc in documents %}
    {{ doc.content }}
{% endfor %}

Answer:
"""

prompt_builder = PromptBuilder(template=prompt_template)
llm = OpenAIGenerator()

# Add components to pipeline
pipeline = Pipeline()
pipeline.add_component("retriever", retriever)
pipeline.add_component("prompt_builder", prompt_builder)
pipeline.add_component("llm", llm)

# Connect the components
pipeline.connect("retriever", "prompt_builder.documents")
pipeline.connect("prompt_builder", "llm")

Run your RAG pipeline:

prompt = "What is the topic of the news?"

result = basic_rag_pipeline.run({
    "retriever": {"text": prompt},
    "prompt_builder": {"query": prompt}
})

# Print final answer
print(result['llm']['replies'][0])

Support 📞

For detailed guides, take a look at our docs. If you have questions or requests you can contact us in our Discord channel.

License

needle-haystack is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

needle_haystack_ai-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

needle_haystack_ai-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file needle_haystack_ai-0.1.0.tar.gz.

File metadata

  • Download URL: needle_haystack_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.4 Darwin/22.1.0

File hashes

Hashes for needle_haystack_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e91c6a59373cffc31a7f31728d81ad11121154367a8525701a24be2bf903a99b
MD5 297978237681f439dd514bfa0a074cd1
BLAKE2b-256 83bf5a6c2af4191ff67800ce92c86ac2e0f2f8d03bec038c6ef158ffb304fffc

See more details on using hashes here.

File details

Details for the file needle_haystack_ai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for needle_haystack_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7bc10b1c6cc50c2e54d538c977e14361dd448c6e18c0f14f3174a20c6ddefbc
MD5 4b4233010c559dcefa81b24a8b87cc0a
BLAKE2b-256 1ac93cda0d9c606cd203a341b9de462a1b0379c5b1308b1caea32c220cadf43c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page