Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,27 @@ This would correspond to a dataset that looked something like

With the schema, the RedisVL library can be used to create, load vectors and perform vector searches
```python
import pandas as pd

from redisvl.index import SearchIndex
from redisvl.query import create_vector_query
from redisvl.query import VectorQuery

# define and create the index
index = SearchIndex.from_yaml("./users_schema.yml"))
# initialize the index and connect to Redis
index = SearchIndex.from_dict(schema)
index.connect("redis://localhost:6379")
index.create()

index.load(pd.read_csv("./users.csv").to_dict("records"))
# create the index in Redis
index.create(overwrite=True)

query = create_vector_query(
["user", "age", "job", "credit_score"],
number_of_results=2,
# load data into the index in Redis (list of dicts)
index.load(data)

query = VectorQuery(
vector=[0.1, 0.1, 0.5],
vector_field_name="user_embedding",
return_fields=["user", "age", "job", "credit_score"],
num_results=3,
)

query_vector = np.array([0.1, 0.1, 0.5]).tobytes()
results = index.search(query, query_params={"vector": query_vector})

results = index.search(query.query, query_params=query.params)

```

Expand Down
8 changes: 7 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ def event_loop():
except RuntimeError:
loop = asyncio.new_event_loop()
yield loop
loop.close()
loop.close()

@pytest.fixture
def clear_db():
redis.flushall()
yield
redis.flushall()
28 changes: 28 additions & 0 deletions docs/api/cache.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

********
LLMCache
********

SemanticCache
=============

.. _semantic_cache_api:

.. currentmodule:: redisvl.llmcache.semantic

.. autosummary::

SemanticCache.__init__
SemanticCache.check
SemanticCache.store
SemanticCache.set_threshold
SemanticCache.threshold
SemanticCache.index
SemanticCache.ttl
SemanticCache.set_ttl


.. autoclass:: SemanticCache
:show-inheritance:
:members:
:inherited-members:
59 changes: 59 additions & 0 deletions docs/api/filter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
******
Filter
******

.. _filter_api:

TagFilter
=========


.. currentmodule:: redisvl.query

.. autosummary::

TagFilter.__init__
TagFilter.to_string


.. autoclass:: TagFilter
:show-inheritance:
:members:
:inherited-members:



TextFilter
==========


.. currentmodule:: redisvl.query

.. autosummary::

TextFilter.__init__
TextFilter.to_string


.. autoclass:: TextFilter
:show-inheritance:
:members:
:inherited-members:


NumericFilter
=============


.. currentmodule:: redisvl.query

.. autosummary::

NumericFilter.__init__
NumericFilter.to_string


.. autoclass:: NumericFilter
:show-inheritance:
:members:
:inherited-members:
6 changes: 5 additions & 1 deletion docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ myst:

```{toctree}
:caption: RedisVL
:maxdepth: 2

redisvl_api
searchindex
query
filter
cache
```

25 changes: 25 additions & 0 deletions docs/api/query.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

*****
Query
*****

VectorQuery
===========

.. _query_api:

.. currentmodule:: redisvl.query

.. autosummary::

VectorQuery.__init__
VectorQuery.set_filter
VectorQuery.get_filter
VectorQuery.query
VectorQuery.params


.. autoclass:: VectorQuery
:show-inheritance:
:members:
:inherited-members:
7 changes: 3 additions & 4 deletions docs/api/redisvl_api.rst → docs/api/searchindex.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

***********
RedisVL API
***********

*****
Index
*****

SearchIndex
===========
Expand Down
45 changes: 22 additions & 23 deletions docs/user_guide/getting_started_01.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -58,7 +58,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -131,7 +131,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -171,7 +171,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -189,15 +189,16 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[32m14:26:12\u001b[0m \u001b[35msam.partee-NW9MQX5Y74\u001b[0m \u001b[34mredisvl.cli.index[17001]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
"\u001b[32m14:26:12\u001b[0m \u001b[35msam.partee-NW9MQX5Y74\u001b[0m \u001b[34mredisvl.cli.index[17001]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user_index\n"
"\u001b[32m00:29:48\u001b[0m \u001b[35msam.partee-NW9MQX5Y74\u001b[0m \u001b[34mredisvl.cli.index[40909]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n",
"\u001b[32m00:29:48\u001b[0m \u001b[35msam.partee-NW9MQX5Y74\u001b[0m \u001b[34mredisvl.cli.index[40909]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. user_index\n",
"\u001b[32m00:29:48\u001b[0m \u001b[35msam.partee-NW9MQX5Y74\u001b[0m \u001b[34mredisvl.cli.index[40909]\u001b[0m \u001b[1;30mINFO\u001b[0m 2. my_index\n"
]
}
],
Expand All @@ -217,7 +218,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -237,48 +238,46 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from redisvl.query import create_vector_query\n",
"from redisvl.query import VectorQuery\n",
"\n",
"# create a vector query returning a number of results\n",
"# with specific fields to return.\n",
"query = create_vector_query(\n",
" return_fields=[\"users\", \"age\", \"job\", \"credit_score\", \"vector_score\"],\n",
" number_of_results=3,\n",
" vector_field_name=\"user_embedding\"\n",
"query = VectorQuery(\n",
" vector=[0.1, 0.1, 0.5],\n",
" vector_field_name=\"user_embedding\",\n",
" return_fields=[\"user\", \"age\", \"job\", \"credit_score\", \"vector_distance\"],\n",
" num_results=3\n",
")\n",
"\n",
"# establish a query vector to search against the data in Redis\n",
"query_vector = np.array([0.1, 0.1, 0.5], dtype=np.float32).tobytes()\n",
"\n",
"# use the SearchIndex instance (or Redis client) to execute the query\n",
"results = index.search(query, query_params={\"vector\": query_vector})"
"results = index.search(query.query, query_params=query.params)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Score: 0\n",
"Document {'id': 'v1:john', 'payload': None, 'vector_score': '0', 'age': '1', 'job': 'engineer', 'credit_score': 'high'}\n",
"Document {'id': 'v1:john', 'payload': None, 'vector_distance': '0', 'user': 'john', 'age': '1', 'job': 'engineer', 'credit_score': 'high'}\n",
"Score: 0\n",
"Document {'id': 'v1:mary', 'payload': None, 'vector_score': '0', 'age': '2', 'job': 'doctor', 'credit_score': 'low'}\n",
"Document {'id': 'v1:mary', 'payload': None, 'vector_distance': '0', 'user': 'mary', 'age': '2', 'job': 'doctor', 'credit_score': 'low'}\n",
"Score: 0.653301358223\n",
"Document {'id': 'v1:joe', 'payload': None, 'vector_score': '0.653301358223', 'age': '3', 'job': 'dentist', 'credit_score': 'medium'}\n"
"Document {'id': 'v1:joe', 'payload': None, 'vector_distance': '0.653301358223', 'user': 'joe', 'age': '3', 'job': 'dentist', 'credit_score': 'medium'}\n"
]
}
],
"source": [
"for doc in results.docs:\n",
" print(\"Score:\", doc.vector_score)\n",
" print(\"Score:\", doc.vector_distance)\n",
" print(doc)\n"
]
},
Expand Down
Loading