Documentation > AI-RAG-NLP-API > Testing OpenSolr Vector Search

Testing OpenSolr Vector Search: Step-by-Step Guide

This tutorial will show you how to test and explore your OpenSolr Vector Search Engine with real examples, including API queries, curl commands, and code snippets in PHP, AJAX, and Python.


1. Overview

OpenSolr lets you build a complete AI-powered search pipeline:

Crawl → Index → Embed → Solr → Search

You can create this entire flow out of the box using the OpenSolr Web Crawler Site Search Solution:
👉 https://opensolr.com/faq/view/web-crawler/46/opensolr-web-crawler-site-search-solution

For setup details, assistance, or pricing information, contact us at:
📧 [email protected]


2. Testing Vector Search Online

You can test your vector search engine directly here:
👉 https://opensolr.com/search/vector?topbar=block&q=climate+disasters+hurricanes+floods+wildfires&in=web&og=yes&locale=&duration=&source=&fresh=yes&lang=

Try using conceptual queries (semantic rather than literal):

  • climate disasters hurricanes floods wildfires
  • space exploration mars colonization economy
  • ancient microbes life beyond earth

These queries will show how your embeddings and vector similarity work in practice.


3. Using the Solr API Directly

Solr Core Example:

https://de9.solrcluster.com/solr/vector/select?wt=json&indent=true&q=*:*&rows=2

Username: 123
Password: 123

3.1 Simple Lexical Query

curl -u 123:123 "https://de9.solrcluster.com/solr/vector/select?q=climate+change&rows=5&wt=json"

3.2 Pure Vector Query (KNN)

curl -u 123:123 "https://de9.solrcluster.com/solr/vector/select?q={!knn%20f=embeddings%20topK=50}[0.123,0.432,0.556,...]&wt=json"

Replace the vector array with your own embedding from the OpenSolr AI NLP API.

3.3 Hybrid Query (Lexical + Vector)

curl -u 123:123 "https://de9.solrcluster.com/solr/vector/select?q={!bool%20should=$lexicalQuery%20should=$vectorQuery}&lexicalQuery={!edismax%20qf=content}climate+change&vectorQuery={!knn%20f=embeddings%20topK=50}[0.12,0.43,0.66,...]&wt=json"

This version mixes traditional keyword scoring with semantic similarity — best of both worlds.


4. Getting Embeddings via OpenSolr API

You can generate embeddings for any text or document using these API endpoints:

Example:

curl -X POST https://opensolr.com/api/nlp/embed -d '{"text": "climate change impact on crops"}' -H "Content-Type: application/json"

Response will include the vector embedding array you can pass to Solr.


5. Example Implementations

PHP Example

<?php
$url = 'https://de9.solrcluster.com/solr/vector/select?wt=json';
$query = '{!bool should=$lexicalQuery should=$vectorQuery}';
$params = [
  'lexicalQuery' => '{!edismax qf=content}climate disasters',
  'vectorQuery'  => '{!knn f=embeddings topK=50}[0.12,0.43,0.56,0.77]'
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, '123:123');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>

AJAX Example

<script>
fetch('https://de9.solrcluster.com/solr/vector/select?wt=json&q={!knn%20f=embeddings%20topK=10}[0.11,0.22,0.33]', {
  headers: {
    'Authorization': 'Basic ' + btoa('123:123')
  }
})
.then(r => r.json())
.then(console.log);
</script>

Python Example

import requests
from requests.auth import HTTPBasicAuth

url = "https://de9.solrcluster.com/solr/vector/select"
params = {
    'q': '{!bool should=$lexicalQuery should=$vectorQuery}',
    'lexicalQuery': '{!edismax qf=content}climate disasters',
    'vectorQuery': '{!knn f=embeddings topK=50}[0.12,0.43,0.56,0.77]',
    'wt': 'json'
}

response = requests.post(url, data=params, auth=HTTPBasicAuth('123', '123'))
print(response.json())

6. Notes

  • You can adjust topK to control how many similar results you want (usually 20–100).
  • If you use {!bool should=should} instead of must, the vector similarity will have more influence on ranking.
  • For best hybrid results, combine both lexical and vector queries.

7. Need Help?

To get started or request a ready-to-use search engine setup:
📧 [email protected]






Review us on Google Business
ISO-9001 CERTIFIED ISO-27001 CERTIFIED