Files
semantica/docs/cookbook/introduction/Vector_Store.ipynb
T

3.8 KiB

Vector Store

Overview

This notebook demonstrates how to store and search vectors using Semantica's vector store modules. You'll learn to use VectorStore and HybridSearch for vector storage and retrieval.

Learning Objectives

  • Use VectorStore to store vectors
  • Search vectors using similarity
  • Use HybridSearch for hybrid search
  • Manage vector metadata

Step 1: Store Vectors

Store vectors in the vector store.

In [ ]:
from semantica.vector_store import VectorStore
from semantica.embeddings import EmbeddingGenerator
import numpy as np

vector_store = VectorStore()
generator = EmbeddingGenerator()

texts = ["Apple Inc.", "Microsoft Corporation", "Amazon Web Services"]
embeddings = generator.generate(texts)

metadata = [
    {"id": "1", "type": "company"},
    {"id": "2", "type": "company"},
    {"id": "3", "type": "service"}
]

vector_ids = vector_store.store_vectors(embeddings, metadata)

print(f"Stored {len(vector_ids)} vectors")
print(f"Vector IDs: {vector_ids[:3]}")

Step 2: Search Vectors

Search for similar vectors.

In [ ]:
query_text = "technology company"
query_embedding = generator.generate([query_text])[0]

results = vector_store.search_vectors(query_embedding, k=3)

print(f"Found {len(results)} similar vectors")
for result in results[:3]:
    print(f"  ID: {result.get('id')}, Score: {result.get('score', 0):.3f}")

Use HybridSearch for combined vector and metadata search.

In [ ]:
from semantica.vector_store import HybridSearch

hybrid_search = HybridSearch()

hybrid_results = hybrid_search.search(
    query_vector=query_embedding,
    vectors=embeddings,
    metadata=metadata,
    vector_ids=vector_ids,
    k=3
)

print(f"Hybrid search found {len(hybrid_results)} results")

Summary

You've learned how to use vector stores:

  • VectorStore: Store and search vectors
  • HybridSearch: Hybrid vector and metadata search

Next: Learn how to generate ontologies in the Ontology notebook.