Build better experiences that grow with you—with accessible, enterprise-grade caching built by the devs who brought you open source Redis.
res11 = r.json().set("newbike", "$", ["Deimos", {"crashes": 0}, None])
print(res11) # >>> True
res12 = r.json().get("newbike", "$")
print(res12) # >>> ['["Deimos", { "crashes": 0 }, null]']
res13 = r.json().get("newbike", "$[1].crashes")
print(res13) # >>> ['0']
res14 = r.json().delete("newbike", "$.[-1]")
print(res14) # >>> [1]
res15 = r.json().get("newbike", "$")
print(res15) # >>> [['Deimos', {'crashes': 0}]]
The best results are the results you were searching for. Make your AI app smarter and faster with streamlined document search, recommendation systems, semantic caching, and Retrieval Augmented Generation (RAG).
# Create a vector index using the HNSW algorithm, 768 dimension length, and inner product distance metric
> FT.CREATE idx-videos ON HASH PREFIX 1 video: SCHEMA content_vector VECTOR HNSW 6 TYPE FLOAT32 DIM 768 DISTANCE_METRIC IP content TEXT metadata TEXT
# Add a video vector with metadata
> HSET video:0 content_vector "\xa4q\t=\xc1\xdes\xbdZ$<\xbd\xd5\xc1\x99<b\xf0\xf2<x[...\xf8<" content "SUMMARY:\nThe video discusses the limitations of MySQL at scale and introduces Redis Enterprise" metadata "{\"id\":\"FQzlq91g7mg\",\"link\":\"https://www.youtube.com/watch?v=FQzlq91g7mg\",\"title\":\"Redis + MySQL in 60 Seconds\"}"
(integer) 3
# Search for videos using a similar vector and the K-nearest neighbors algorithm
> FT.SEARCH idx-videos "* => [KNN 3 @content_vector $vector AS vector_score]" RETURN 3 metadata content vector_score SORTBY vector_score LIMIT 0 3 PARAMS 2 vector "\b[\xb7;\x81\x12\x9c\xbc\xc6!...\xfe<" DIALECT 2
Use Redis as your NoSQL database to build fast, reliable apps that make five-9s uptime look easy.
# Connect to Redis
r = Redis(host='localhost', port=6379, decode_responses=True)
# Create a search index on documents with prefix "doc:"
try:
r.ft("idx:docs").create_index(
fields=[
TextField("$.title", as_name="title"),
TextField("$.content", as_name="content"),
TagField("$.tags", as_name="tags")
],
definition=IndexDefinition(prefix=["doc:"], index_type=IndexType.JSON)
)
except Exception as e:
print(f"Index creation skipped: {e}")
# Add some documents
doc1 = {
"title": "Redis JSON Guide",
"content": "Learn how to use Redis with JSON and search.",
"tags": "redis,guide,search"
}
doc2 = {
"title": "Introduction to Vector Search",
"content": "Explore semantic search with Redis.",
"tags": "vector,search,redis"
}
doc3 = {
"title": "Caching Best Practices",
"content": "Speed up your apps using Redis caching.",
"tags": "cache,performance,redis"
}
r.json().set("doc:1", Path.root_path(), doc1)
r.json().set("doc:2", Path.root_path(), doc2)
r.json().set("doc:3", Path.root_path(), doc3)
# Search for documents that mention "search"
query = Query("search")
res = r.ft("idx:docs").search(query)
# Print matching documents
for doc in res.docs:
print(f"{doc.id}:\n Title: {doc.title}\n Tags: {doc.tags}\n")