CS

AI Development

Practical AI development reference: embeddings, vector search, Python AI libraries, and core machine learning fundamentals.

What this covers

Concepts, tools, and practical techniques for AI development: embeddings and vector search, key Python AI libraries, and core machine learning fundamentals. For building a full retrieval-augmented generation pipeline, see RAG; for local model serving, see Ollama; for connecting an AI assistant to external tools, see MCP; for wiring AI into a Drupal site, see AI in Drupal.

When to use it

  • Choosing an embedding model or vector similarity metric for a semantic search feature
  • Deciding between transformers and sentence-transformers, or picking another Python AI library, for an NLP task
  • Picking a machine learning technique (regression, SVM, random forest, nearest neighbors) for a predictive-modeling task

AI Fundamentals

Vector Databases and Embeddings

Vector databases store high-dimensional vectors for efficient semantic searches. Unlike traditional keyword-based databases, they allow similarity searches using embeddings.

Key Concepts:

  • Embeddings: Numerical representations of text, images, or audio in vector space.
  • Semantic Search: Retrieves information based on meaning, not exact keywords.
  • Vector Similarity Metrics: Cosine similarity, Euclidean distance, Manhattan distance.

Recommended Resources:

For building the retrieval and generation pipeline on top of these fundamentals, see RAG.

Python AI Libraries

Transformers Library

from transformers import AutoModel, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModel.from_pretrained("bert-base-uncased")
inputs = tokenizer("Hello world", return_tensors="pt")
outputs = model(**inputs)

Transformers vs Sentence Transformers:

Featuretransformerssentence-transformers
FocusGeneral NLP tasksSentence/document embeddings
OutputToken embeddings, logitsSemantic embeddings ready for similarity search
Ease of useRequires manual pooling for sentencesencode() method for direct vectors
ModelsBERT, GPT, T5MiniLM, mpnet, etc.

Other Libraries

  • PyTorch: Neural networks
  • NumPy / Pandas: Data handling
  • Scikit-learn: ML algorithms
  • PEFT: Efficient fine-tuning of LLMs

AI Implementation Best Practices

  1. Choose models suited to task and hardware.
  2. Decide local (Ollama) vs cloud-based deployment based on privacy and scalability.
  3. Use efficient embeddings for semantic search.
  4. Combine retrieval systems with generative models (RAG) for knowledge-intensive tasks.
  5. Monitor resource usage and optimize performance.

Machine Learning Fundamentals

Core Concepts:

  • Bias-Variance Tradeoff: Balance simplicity and flexibility.
  • Central Limit Theorem: Sample means converge to normal distribution.
  • Law of Large Numbers: Larger datasets provide more reliable estimates.

Supervised Learning:

  • Linear Regression: Predict continuous values.
  • R-squared: Model fit metric.
  • SVM: Optimal hyperplane classification.

Ensemble Methods:

  • Random Forest: Reduces overfitting, handles missing data, provides feature importance.

Unsupervised Learning:

  • Nearest Neighbors: Classifies based on similarity, sensitive to irrelevant features.

Neural Networks:

  • Layered structure, learns patterns via backpropagation, foundation for deep learning.

Data Visualization:

  • Seaborn: Advanced statistical plots, integrates with pandas.

Practical Applications:

  • Predictive modeling (e.g., elections)
  • Trend analysis from demographic or historical data