Skip to content

Commit 3ddd111

Browse files
julian-rischclaude
andauthored
Add Apache Solr integration page (#588)
* Add Apache Solr integration page Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Use the on-black Solr logo variant for dark backgrounds Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 1829ea3 commit 3ddd111

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

‎integrations/solr.md‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
layout: integration
3+
name: Apache Solr
4+
description: Use an Apache Solr search server as a Document Store with Haystack
5+
authors:
6+
- name: deepset
7+
socials:
8+
github: deepset-ai
9+
twitter: deepset_ai
10+
linkedin: https://www.linkedin.com/company/deepset-ai/
11+
pypi: https://pypi.org/project/solr-haystack
12+
repo: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/solr
13+
type: Document Store
14+
report_issue: https://github.com/deepset-ai/haystack-core-integrations/issues
15+
logo: /logos/solr.png
16+
version: Haystack 2.0
17+
toc: true
18+
---
19+
20+
### Table of Contents
21+
22+
- [Overview](#overview)
23+
- [Installation](#installation)
24+
- [Usage](#usage)
25+
- [License](#license)
26+
27+
## Overview
28+
29+
[![PyPI - Version](https://img.shields.io/pypi/v/solr-haystack.svg)](https://pypi.org/project/solr-haystack)
30+
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/solr-haystack.svg)](https://pypi.org/project/solr-haystack)
31+
[![test](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/solr.yml/badge.svg)](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/solr.yml)
32+
33+
[Apache Solr](https://solr.apache.org/) is a widely used open source search server built on Apache Lucene. Since Solr 9, it ships a `DenseVectorField` and the `{!knn}` query parser, so it can serve both keyword (BM25) and dense vector retrieval — everything a RAG pipeline needs from a Document Store.
34+
35+
The integration provides:
36+
37+
- `SolrDocumentStore`, with sync and async support for all operations
38+
- `SolrBM25Retriever`, `SolrEmbeddingRetriever`, and `SolrHybridRetriever`
39+
- Full metadata filtering support, including exact round-trips of Python metadata types
40+
- Extended methods such as `delete_by_filter`, `update_by_filter`, `count_documents_by_filter`, and metadata field introspection
41+
42+
The Document Store requires Solr 9.6 or newer and talks to Solr over its JSON HTTP API via `httpx`, so no Solr client library is needed.
43+
44+
## Installation
45+
46+
```console
47+
pip install solr-haystack
48+
```
49+
50+
## Usage
51+
52+
Start a Solr instance, for example with Docker:
53+
54+
```console
55+
docker run -d -p 8983:8983 solr:10 solr-precreate haystack
56+
```
57+
58+
Then initialize a `SolrDocumentStore` connected to the instance and write documents to it. By default, the store manages the schema itself: it creates the fields it needs and disables Solr's schemaless field guessing.
59+
60+
```python
61+
from haystack import Document
62+
from haystack_integrations.document_stores.solr import SolrDocumentStore
63+
64+
document_store = SolrDocumentStore(
65+
url="http://localhost:8983/solr",
66+
core="haystack",
67+
embedding_dim=768,
68+
)
69+
70+
document_store.write_documents(
71+
[Document(content="This is first"), Document(content="This is second")]
72+
)
73+
print(document_store.count_documents())
74+
```
75+
76+
The store reads the `SOLR_URL`, `SOLR_USERNAME`, and `SOLR_PASSWORD` environment variables by default, so credentials never need to appear in code or serialized pipelines.
77+
78+
### Retrieval
79+
80+
The integration supports different retrieval types through different retriever components:
81+
82+
- [`SolrBM25Retriever`](https://docs.haystack.deepset.ai/docs/solrbm25retriever): A keyword-based retriever that fetches documents matching a query using Solr's BM25 similarity.
83+
- [`SolrEmbeddingRetriever`](https://docs.haystack.deepset.ai/docs/solrembeddingretriever): Compares the query and document embeddings using Solr's `{!knn}` dense vector search and fetches the documents most relevant to the query.
84+
- [`SolrHybridRetriever`](https://docs.haystack.deepset.ai/docs/solrhybridretriever): A SuperComponent that embeds the query, runs BM25 and embedding retrieval over the same core, and fuses the results with reciprocal rank fusion.
85+
86+
Here is a hybrid retrieval example — one component embeds the query, retrieves with both methods, and merges the result lists:
87+
88+
```python
89+
from haystack.components.embedders import SentenceTransformersTextEmbedder
90+
from haystack_integrations.components.retrievers.solr import SolrHybridRetriever
91+
from haystack_integrations.document_stores.solr import SolrDocumentStore
92+
93+
document_store = SolrDocumentStore(core="haystack", embedding_dim=384)
94+
retriever = SolrHybridRetriever(
95+
document_store=document_store,
96+
embedder=SentenceTransformersTextEmbedder(model="sentence-transformers/all-MiniLM-L6-v2"),
97+
)
98+
retriever.warm_up()
99+
result = retriever.run(query="Apache Solr")
100+
print(result["documents"])
101+
```
102+
103+
### Metadata
104+
105+
Metadata values keep their Python types across the round-trip: the integer `1`, the string `"1"`, the float `1.0`, and `True` stay four distinct values. Filters work on all metadata fields, and extended methods let you delete or update documents by filter, count documents and unique metadata values, and inspect metadata fields — each with an async twin.
106+
107+
## License
108+
109+
`solr-haystack` is distributed under the terms of the [Apache-2.0 license](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/solr/LICENSE.txt).

‎logos/solr.png‎

33.3 KB
Loading

0 commit comments

Comments
 (0)