AI Model Wiki

    Skip to main content
    22 min
    Lesson 3 of 4

    Feature Store and RAG

    From the course Google Vertex AI Platform

    Build enterprise AI applications with Vertex AI Feature Store and Vector Search.

    Vertex AI Feature Store

    Create and Serve Features

    from google.cloud.aiplatform import featurestore
    
    # Create feature store
    fs = featurestore.Featurestore.create(
        featurestore_id="customer_features",
        online_store_fixed_node_count=3  # Online serving nodes
    )
    
    # Create entity type
    entity_type = fs.create_entity_type(
        entity_type_id="customer",
        description="Customer profile features"
    )
    
    # Create features
    entity_type.batch_create_features(
        feature_configs={
            "age": featurestore.Feature.Meta(value_type=featurestore.Feature.ValueType.INT64),
            "purchase_count_7d": featurestore.Feature.Meta(value_type=featurestore.Feature.ValueType.INT64),
            "lifetime_value": featurestore.Feature.Meta(value_type=featurestore.Feature.ValueType.DOUBLE),
        }
    )
    
    # Real-time feature serving
    features = entity_type.read(
        entity_ids=["customer_123"],
        feature_ids=["age", "purchase_count_7d", "lifetime_value"]
    )
    

    Vertex AI Vector Search

    RAG Implementation

    from google.cloud.aiplatform.matching_engine import (
        MatchingEngineIndex, 
        MatchingEngineIndexEndpoint
    )
    import vertexai
    from vertexai.language_models import TextEmbeddingModel
    
    # Create index
    index = MatchingEngineIndex.create_tree_ah_index(
        display_name="documents-index",
        dimensions=768,
        approximate_neighbors_count=150,
        distance_measure_type="DOT_PRODUCT_DISTANCE"
    )
    
    # Embed documents
    embed_model = TextEmbeddingModel.from_pretrained("text-embedding-004")
    
    def embed_document(text):
        embedding = embed_model.get_embeddings([text])[0]
        return embedding.values
    
    # Query (RAG pipeline)
    query_embedding = embed_document(user_query)
    
    endpoint = MatchingEngineIndexEndpoint(index_endpoint_name=endpoint_name)
    neighbors = endpoint.find_neighbors(
        deployed_index_id="deployed_index",
        queries=[query_embedding],
        num_neighbors=5
    )
    
    # Use retrieved documents with Gemini
    context = "
    ".join([get_document_text(n.id) for n in neighbors[0]])
    response = model.generate_content(
        f"Context:
    {context}
    
    Question: {user_query}
    
    Answer:"
    )
    

    Best Practices Summary

    • Use Feature Store for consistent feature serving across training and inference
    • Implement Vector Search for scalable semantic retrieval
    • Monitor model performance and data drift continuously
    • Version all models, datasets, and pipelines for reproducibility
    • Use VPC Service Controls for data exfiltration prevention

    Key Takeaways

    • •Feature Store provides consistent, low-latency feature serving for online prediction
    • •Vector Search enables scalable semantic retrieval for RAG applications
    • •Integrated platform connects feature engineering, model training, and serving
    • •VPC Service Controls and IAM ensure enterprise security compliance
    0 of 4 lessons marked complete

    Progress is kept in this browser only.