Guide To Vectors
  • Introduction
  • Guide to this Book
  • API documentation
  • Python SDK Documentation
  • Learn about vectors
    • 🌱Introduction to vectors
      • 🌱Applications of vectors
        • 🌱Vectors for classification
      • 🌱Limitations of vectors
    • 🌱What is vector search?
      • 🌱How to vector search
      • 🌱How to build image to text search using code
      • 🧍Try vector search with playground!
      • 💻Vector search with code
    • 🌱Terminology Guide
  • Unlock Vector AI
    • 🔍Inserting Into Vector AI
      • 🧍Inserting with playground
      • 💻Inserting with API
        • 💻Inserting with API - encoding while inserting (recommended)
        • 💻Inserting with API - encoding before inserting
        • 💻Inserting with API - encoding after inserting
      • 🧍How to check insertion succeeded
    • 🔍Searching with Vector AI
      • 🌱How to search with the playground
      • 🌱Combining with traditional search
        • 🧍How to combine exact text search with vector search
        • 💻How to add exact text search to vector search
      • 🌱Personalisation with vector search
        • 💻Personalised search/recommendations with vector search
      • 🌱Chunk search
        • 💻How To Chunk Search
        • 💻How To Do MultiVector Chunk Search
        • 💻How to do multi step chunk search
      • 🧍How to diversify search results
    • 🔍Clustering
      • 🌱Clustering Vectors From Deep Learning models
    • 🔍Aggregation
      • 💻Writing Your First Aggregation
      • 💻Publishing Your First Aggregation
    • 🔍Experimentation
      • 🌱Vector Evaluation
        • 🌱Evaluate Vector Bias
    • 🔍Jobs
      • 💻Tagging Jobs
      • 💻Chunking Jobs
      • 💻Encoding Jobs
      • 🧍List all jobs (active and inactive)
    • 🔍Encoding
    • 🔍Maintenance & Monitoring
      • 🧍How to view your collections
      • 💻How to share your collections
      • 💻How to back up your collections
      • 💻How to change name of a collection field
      • 💻How to change the schema of a collection
      • 💻How to remove a field in a collection
      • 💻How to request a read API key
  • Tutorials
    • 💻How to turn data into Vectors (code)
      • 💻How to turn text into Vectors
      • 💻How to turn images Into Vectors
      • 💻How to turn audio into Vectors
    • 💻Image Search For Developers
    • 💻How To Combine Different Vectors For Search
    • 💻How To Combine Different Vectors With Exact Matching Text
    • 💻Semantic NLP search with FAISS and VectorHub
  • ABOUT
    • Credits
    • Philosophy
    • Glossary
Powered by GitBook
On this page

Was this helpful?

  1. Learn about vectors
  2. What is vector search?

Vector search with code

A guide to building vector search with Vector AI

Assumed Knowledge: Vectors, Vector Search, Python (Basic level) Target Audience: General developer, Data scientist, Python developer Reading Time: 5 minutes Requirements: Python 3.6 or Python 3.7

Below, we build a simple example of image search with Vector AI

  1. We get the data on a document-based approach.

collection_name = 'pokemon_images'

documents = []
for i in range(1, 20):
    documents.append({
        'image': 'https://assets.pokemon.com/assets/cms2/img/pokedex/full/{}.png'.format(f'{i:03}'),
        'pokemon_id' : str(i),
        '_id': i
    })

2. We encode the images and instantiate the Vector AI client. If you do not have a username or API key, simply request one Pythonically from this link.

from vectorai.client import ViClient
vi_client = ViClient(username, api_key, url)
from vectorai.models.deployed import ViImage2Vec
image_encoder = ViImage2Vec(username, api_key, url)
for doc in documents:
    doc['image_vector_'] = image_encoder.encode(doc['image'])

3. Add your documents to your index using insert_documents.

vi_client.insert_documents(collection_name, documents)

4. Search your documents using search.

# Search the application
image_url = 'https://assets.pokemon.com/assets/cms2/img/pokedex/full/003.png')
search_results = vi_client.search(
collection_name,
image_encoder.encode(image_url), search_fields=['image_vector_'],
page_size=5)

# Show the results!
vi_client.show_json(search_results, image_fields=['image'], image_width=150)

PreviousTry vector search with playground!NextTerminology Guide

Last updated 4 years ago

Was this helpful?

🌱
💻