Editing
Embeddings Vector Dbs
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== <span style="color: #FFFFFF;">Applying</span> == '''Generating and storing embeddings with Sentence Transformers + Chroma:''' <syntaxhighlight lang="python"> from sentence_transformers import SentenceTransformer import chromadb import numpy as np # Load embedding model model = SentenceTransformer("BAAI/bge-m3") # Sample documents docs = [ "Neural networks are the foundation of deep learning.", "The heart pumps blood through the circulatory system.", "Python is a popular programming language for data science.", "Transformers use self-attention mechanisms for NLP tasks.", "The mitochondria are the powerhouse of the cell.", ] # Generate embeddings embeddings = model.encode(docs, normalize_embeddings=True) print(f"Embedding shape: {embeddings.shape}") # (5, 1024) # Store in vector database client = chromadb.Client() collection = client.create_collection("knowledge_base") collection.add( documents=docs, embeddings=embeddings.tolist(), ids=[f"doc_{i}" for i in range(len(docs))] ) # Semantic search query = "How do attention mechanisms work?" query_embedding = model.encode([query], normalize_embeddings=True).tolist() results = collection.query( query_embeddings=query_embedding, n_results=2 ) print(results["documents"]) # [["Transformers use self-attention mechanisms for NLP tasks.", # "Neural networks are the foundation of deep learning."]] </syntaxhighlight> ; Vector database selection guide : '''Local/development''' β Chroma (in-memory, file-backed), FAISS (library) : '''Self-hosted production''' β Qdrant (Rust, great performance), Weaviate (rich features), Milvus (scale) : '''Managed cloud''' β Pinecone (simplest API), Weaviate Cloud, Zilliz Cloud : '''Existing PostgreSQL stack''' β pgvector extension (good for <10M vectors) : '''Multimodal (text + image)''' β Weaviate, Qdrant (both support multiple vector types) </div> <div style="background-color: #8B4500; color: #FFFFFF; padding: 20px; border-radius: 8px; margin-bottom: 15px;">
Summary:
Please note that all contributions to BloomWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BloomWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information