# NeedleRetriever

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/retrievers/needle/NeedleRetriever)

NeedleRetriever retrieves relevant documents or context from a Needle collection
based on a search query.

## Signature

```python
NeedleRetriever()
```

## Description

**Setup:**

Install the `needle-python` library and set your Needle API key.

.. code-block:: bash

    pip install needle-python
    export NEEDLE_API_KEY="your-api-key"

**Key init args:**

- `needle_api_key` (Optional[str]): The API key for authenticating with Needle.
- `collection_id` (str): The ID of the Needle collection to search in.
- `client` (Optional[NeedleClient]): An optional instance of the NeedleClient.
- `top_k` (Optional[int]): Maximum number of results to return.

**Usage:**

.. code-block:: python

from langchain_community.retrievers.needle import NeedleRetriever

retriever = NeedleRetriever(
    needle_api_key="your-api-key",
    collection_id="your-collection-id",
    top_k=10  # optional
)

results = retriever.retrieve("example query")
for doc in results:
    print(doc.page_content)

## Extends

- `BaseRetriever`
- `BaseModel`

## Properties

- `client`
- `needle_api_key`
- `collection_id`
- `top_k`

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/4b280287bd55b99b44db2dd849f02d66c89534d5/libs/community/langchain_community/retrievers/needle.py#L9)