Vector Stores API¶
Milvus (Llama Stack)¶
llama_stack ¶
Classes¶
LSVectorStore ¶
LSVectorStore(
embedding_model: LSEmbeddingModel,
client: LlamaStackClient,
provider_id: str,
reuse_collection_name: str | None = None,
distance_metric: str | None = None,
)
Bases: BaseVectorStore
LLamaStack client wrapper used for communication with vector store (single index/collection).
Source code in ai4rag/rag/vector_store/llama_stack.py
Functions¶
search ¶
search(
query: str,
k: int,
include_scores: bool = False,
search_mode: str = "vector",
ranker_strategy: str | None = None,
ranker_k: int | None = None,
ranker_alpha: float | None = None,
**kwargs
) -> list[Document] | list[tuple[Document, float]]
Search for the chunks relevant to the query.
Parameters:
-
query(str) –Question / query for which the similarity search will be executed.
-
k(int) –Number of chunks to be returned as a result of similarity search
-
include_scores(bool, default:False) –If True, similarity scores will be returned in the response
-
search_mode(str, default:"vector") –Search mode: "vector" or "hybrid".
-
ranker_strategy(str | None, default:None) –Ranking strategy for hybrid search: "rrf", "weighted", or "normalized". Empty string means no ranker (used for non-hybrid modes).
-
ranker_k(int | None, default:None) –Parameter k for the ranking function. 0 means not set.
-
ranker_alpha(float, default:None) –Alpha parameter for weighted ranking strategy. 1 means not set (vector-only sentinel).
Returns:
-
list[Document] | list[tuple[Document, float]]–List of chunks as Document instances with or without scores, depending on the input.
Source code in ai4rag/rag/vector_store/llama_stack.py
add_documents ¶
Add documents to the collection.
Parameters:
-
documents(Sequence[Document]) –Documents to add to the collection.
Source code in ai4rag/rag/vector_store/llama_stack.py
clean_collection ¶
ChromaDB¶
chroma ¶
Classes¶
ChromaVectorStore ¶
ChromaVectorStore(
embedding_model: BaseEmbeddingModel,
reuse_collection_name: str | None = None,
distance_metric: str = "cosine",
document_name_field: str = "document_id",
chunk_sequence_number_field: str = "sequence_number",
**kwargs
)
Bases: BaseVectorStore
Class representing single index in the chroma vector database.
Parameters:
-
embedding_model(BaseEmbeddingModel) –Instance used for embedding documents and user's queries.
-
reuse_collection_name(str, default:None) –Name of the collection that will be created as a vector store.
-
distance_metric(str, default:"cosine") –Metric that will be used to calculate similarity score between vectors.
-
document_name_field(str, default:"document_id") –Default document ID field name.
-
chunk_sequence_number_field(str, default:"chunk_sequence_number") –Default chunk sequence number field name.
Source code in ai4rag/rag/vector_store/chroma.py
Attributes¶
Functions¶
clear ¶
count ¶
Count the number of shards in the vector store.
Returns:
-
int–Number of shards in the vector store.
add_documents ¶
Embed and add documents to the vector store.
Parameters:
-
documents(list) –Documents to be embedded and added to the vector store.
Returns:
-
list[str]–List of documents IDs.
Source code in ai4rag/rag/vector_store/chroma.py
search ¶
search(
query: str, k: int = 5, include_scores: bool = False, **kwargs: Any
) -> list[Document] | list[tuple[Document, float]]
Searches for documents most similar to the query.
The method is designed as a wrapper for respective LangChain VectorStores' similarity search methods. Therefore, additional search parameters passed in kwargs should be consistent with those methods, and can be found in the LangChain documentation.
Parameters:
-
query(str) –Query for which grounding documents will be searched for.
-
k(int, default:5) –Number of documents to retrieve
-
include_scores(bool, default:False) –Whether similarity scores of found documents should be returned.
Returns:
-
list[Document] | list[tuple[Document, float]]–Found documents with or without scores.
Source code in ai4rag/rag/vector_store/chroma.py
window_search ¶
window_search(query: str, k: int = 5, include_scores: bool = False, window_size: int = 2, **kwargs: Any) -> list
Searches for documents most similar to the query and extend a document (a chunk) to its adjacent chunks (if they exist) from the same origin document.
The method is designed as a wrapper for respective LangChain VectorStores' similarity search methods. Therefore, additional search parameters passed in kwargs should be consistent with those methods, and can be found in the LangChain documentation.
Parameters:
-
query(str) –Query for which grounding documents will be searched for.
-
k(int, default:5) –Number of documents to retrieve
-
include_scores(bool, default:False) –Whether similarity scores of found documents should be returned.
-
window_size(int, default:2) –Number of chunks from right and left side of the original chunk.
Returns:
-
list–Found documents with or without scores.
Source code in ai4rag/rag/vector_store/chroma.py
delete ¶
Delete by vector ID or other criteria. Sor more details see LangChain documentation https://python.langchain.com/api_reference/core/vectorstores/langchain_core.vectorstores.base.VectorStore.html#langchain_core.vectorstores.base.VectorStore