Solr
LangStream allows you to use Apache Solr as a vector database. This is useful if you want to use a vector database that is hosted on-premises or in your own cloud environment.
You can find more about how to perform Vector Search in Apache Solr in the official documentation
Connecting to Solr
To use Apache Solr as a vector database, create a "vector-database" resource in your configuration.yaml file.
Explanation for the parameters:
username: the username
password: the password
host: the host
port: the port, usually it is 8983
collection-name: the name of the collection to connect to
Currently LangStream supports connecting to one Collection at a time, so you need to create a separate resource for each Collection.
LangStream uses the official Apache Solr Java client to connect to Solr.
Special assets for Apache Solr Cloud
You can use both Solr and Solr Cloud. If you use Solr Cloud then you can also manage the collections using the Solr Cloud API.
To do that, you need to create special assets in your pipeline: "solr-collection".
Here is an example of creating a collection named "documents" with a dense vector, as required to perform Vector Similarity Searches:
As you can see in the "create-statements" section above, you can configure a number of "commands" that translate to Solr API calls. You can invoke any of the APIs, for each command you have to declare:
the "api" you want to call: "/schema" or "/api/collections"
the body of the HTTP Request, as a JSON string
you can also set the HTTP method, if you want to use something different than "POST"
If you set "api" to "/schema" then you are using the Solr Schema API. If you set "api" to "/api/collections" then you are using the Solr Collections API.
Querying Solr
Use the "query-vector-db" agent to query Solr with the following parameters:
As usual you can use the '?' symbol as a placeholder for the fields that you specify in the "q" section.
For Apache Solr, the "query" field requires a JSON that describes the parameters to pass in the Solr query. Usually you provide a value for "q" for the main query string, and then add other parameters.
In the example above, we are using the "knn" query parser to perform a Vector Similarity Search.
Writing to Solr
Use the "vector-db-sink" agent to write to Solr with the following parameters:
Set the collection-name to the name of the collection you want to write to, and define the fields in the "fields" list. This works similarly to the 'compute' agent, where you define the name of the field and the expression to compute the value of the field.
Configuration
Check out the full configuration properties in the API Reference page.
Last updated