|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdata_structures.AbstractSearchStructure
public abstract class AbstractSearchStructure
This abstract class abstracts the bdb environment creation and name to id mapping operations from the actual indexing structures. In the future we can support multi-threaded indexing and querying.
Field Summary | |
---|---|
protected int |
cachePercent
The percentage of the total memory given to the program that will be used as the BDB cache. |
protected int |
cacheSize
The total memory given to the program that will be used as the BDB cache. |
protected boolean |
countSizeOnLoad
Whether the load counter should be initialized when the database is loaded by counting the id-name mappings. |
protected com.sleepycat.je.Environment |
dbEnv
The database environment. |
protected com.sleepycat.je.Database |
idToNameBDB
Berkeley db holding id to name mappings, required for name look-up during nearest neighbor search. |
protected int |
idToNameMappings
Counts the number of persisted id to name mappings. |
protected int |
loadCounter
Keeps track of the total number of indexed vectors, acts as an auto-increment primary key field. |
protected int |
maxNumVectors
The maximum number of vectors that can be indexed. |
protected com.sleepycat.je.Database |
nameToIdBDB
Berkeley db holding name to id mappings, required during indexing to fast check if a name is already indexed. |
protected int |
numIndexingThreads
The number of threads to use during indexing. |
protected boolean |
readOnly
Whether the db should open only for read access. |
protected int |
syncRate
The rate at which the disk-based indexed should be updated. |
private long |
totalInternalVectorIndexingTime
Average time taken for internal vector indexing operations. |
private long |
totalNameMappingTime
Average time taken to create a name to id and the reverse mapping. |
private long |
totalVectorIndexingTime
Average total time taken to index a vector. |
protected boolean |
transactional
Whether the environment will be transactional. |
protected int |
vectorLength
The length of the raw vectors being indexed. |
Constructor Summary | |
---|---|
AbstractSearchStructure(int vectorLength,
int loadCounter,
int maxNumVectors,
boolean readOnly,
boolean countSizeOnLoad)
This constructor can be used when we do not want persistence. |
Method Summary | |
---|---|
void |
close()
This method closes the BDB environment and databases! |
protected abstract void |
closeInternal()
Each subclass should implement this method to close the BDB databases that it uses. |
Answer |
computeNearestNeighbors(int k,
double[] queryVector)
This method returns an array of Result objects, corresponding to the k nearest neighbors' ids, names and their distances from the query vector, ordered by lowest distance. |
protected abstract com.aliasi.util.BoundedPriorityQueue<Result> |
computeNearestNeighborsInternal(int k,
double[] queryVector)
This method returns a bounded priority queue of Result objects, corresponding to the k nearest neighbors' ids and their distances from the query vector, ordered by lowest distance. |
private void |
createMapping(int id,
java.lang.String name,
com.sleepycat.je.Transaction txn)
This method is used to create a persistent mapping between a given id and name. |
private void |
createOrOpenBDBDbs()
This method creates and/or opens the BDB dbs. |
private void |
createOrOpenBDBEnv(java.lang.String BDBEnvHome)
This method creates and/or opens the BDB environment in the supplied directory. |
protected void |
createOrOpenBDBEnvAndDbs(java.lang.String BDBEnvHome)
This method creates or opens (if it already exists) the BDB environment and the BDB dbs. |
java.lang.String |
getExternalId(int id,
com.sleepycat.je.Transaction txn)
This method returns the name or other external unique identifier of the image which was assigned the given internal id. |
int |
getInternalId(java.lang.String name,
com.sleepycat.je.Transaction txn)
This method returns the internal id assigned in the image with the given name or other external unique identifier. |
int |
getLoadCounter()
Returns the current value of the loadCounter. |
boolean |
indexVector(java.lang.String name,
double[] vector)
Updates the index with the given vector. |
protected abstract void |
indexVectorInternal(int id,
double[] vector,
com.sleepycat.je.Transaction txn)
This method should be implemented in all subclasses and do the operations required for indexing the given vector and id. |
boolean |
isIndexed(java.lang.String name,
com.sleepycat.je.Transaction txn)
Checks if the vector with the given name is already indexed. |
void |
outputIndexingTimes()
This method can be called to output indexing time measurements. |
protected abstract void |
outputIndexingTimesInternal()
Index specific time measurements. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int numIndexingThreads
protected int syncRate
protected com.sleepycat.je.Database nameToIdBDB
protected com.sleepycat.je.Database idToNameBDB
protected com.sleepycat.je.Environment dbEnv
protected final boolean transactional
protected final int cachePercent
protected final int cacheSize
protected int idToNameMappings
protected int vectorLength
protected final int maxNumVectors
protected int loadCounter
private long totalNameMappingTime
private long totalInternalVectorIndexingTime
private long totalVectorIndexingTime
protected boolean countSizeOnLoad
protected boolean readOnly
Constructor Detail |
---|
public AbstractSearchStructure(int vectorLength, int loadCounter, int maxNumVectors, boolean readOnly, boolean countSizeOnLoad)
vectorLength
- The dimensionality of the VLAD vectors being indexed.loadCounter
- The initial value of the loadCounter.maxNumVectors
- The maximum number of vectors which we allow to be indexed.readOnly
- If true the persistent store will opened only for read access (allows multiple opens).countSizeOnLoad
- Whether the loadCounter will be initialized by the size of the persistent store.Method Detail |
---|
public int getLoadCounter()
protected void createOrOpenBDBEnvAndDbs(java.lang.String BDBEnvHome) throws java.lang.Exception
BDBEnvHome
- The directory where the BDB environment will be created.
java.lang.Exception
private void createOrOpenBDBEnv(java.lang.String BDBEnvHome) throws java.lang.Exception
BDBEnvHome
- The directory where the BDB environment will be created.
java.lang.Exception
private void createOrOpenBDBDbs() throws java.lang.Exception
java.lang.Exception
public void close() throws java.lang.Exception
java.lang.Exception
protected abstract void closeInternal()
public boolean isIndexed(java.lang.String name, com.sleepycat.je.Transaction txn)
name
- The name the vector to be indexed.txn
- A transaction handle.
public int getInternalId(java.lang.String name, com.sleepycat.je.Transaction txn) throws java.lang.Exception
name
- The name or other external unique identifier of the image.txn
- A transaction handle.
java.lang.Exception
private void createMapping(int id, java.lang.String name, com.sleepycat.je.Transaction txn)
id
- The assigned id.name
- The name.txn
- A transaction handle.public java.lang.String getExternalId(int id, com.sleepycat.je.Transaction txn) throws java.lang.Exception
id
- The id of the image.txn
- A transaction handle.
java.lang.Exception
protected abstract com.aliasi.util.BoundedPriorityQueue<Result> computeNearestNeighborsInternal(int k, double[] queryVector) throws java.lang.Exception
k
- The number of nearest neighbors to return.queryVector
- The query vector.
java.lang.Exception
public Answer computeNearestNeighbors(int k, double[] queryVector) throws java.lang.Exception
k
- The number of nearest neighbors to return.queryVector
- The query vector.
java.lang.Exception
public boolean indexVector(java.lang.String name, double[] vector) throws java.lang.Exception
name
- The name of the vector.vector
- The vector.
java.lang.Exception
protected abstract void indexVectorInternal(int id, double[] vector, com.sleepycat.je.Transaction txn) throws java.lang.Exception
id
- The id of the vector to be indexed.vector
- The vector to be indexed.txn
- A transaction handle.
java.lang.Exception
public void outputIndexingTimes()
protected abstract void outputIndexingTimesInternal()
loadCounter
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |